当前位置: 首页>>代码示例>>Golang>>正文


Golang DenseMatrix.GetMatrix方法代码示例

本文整理汇总了Golang中github.com/skelterjohn/go/matrix.DenseMatrix.GetMatrix方法的典型用法代码示例。如果您正苦于以下问题:Golang DenseMatrix.GetMatrix方法的具体用法?Golang DenseMatrix.GetMatrix怎么用?Golang DenseMatrix.GetMatrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/skelterjohn/go/matrix.DenseMatrix的用法示例。


在下文中一共展示了DenseMatrix.GetMatrix方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getNextLocations

func getNextLocations(piece byte, allMoves *matrix.DenseMatrix, ellipse *matrix.DenseMatrix, baseNode *node.Node) []*node.Node {
	result := make([]*node.Node, 0, 20)

	x := baseNode.GetX()
	y := baseNode.GetY()
	next := baseNode.GetStep() + 1

	// Start with the single move board
	var singleMove *matrix.DenseMatrix
	switch piece {
	case Pawn:
		singleMove = singlePawnMove
	case Rook:
		singleMove = singleRookMove
	case Knight:
		singleMove = singleKnightMove
	case Bishop:
		singleMove = singleBishopMove
	case Queen:
		singleMove = singleQueenMove
	case King:
		singleMove = singleKingMove
	case Puppy:
		singleMove = singlePuppyMove
	}
	singleMove = shiftMatrix(singleMove, x-8, y-8)
	singleMove = singleMove.GetMatrix(7, 0, 8, 8)

	// fmt.Println("(", x, ", ", y, ")")
	// fmt.Println("Single Move: \n", singleMove)

	// fmt.Println("\nAll Moves: \n", allMoves)
	// fmt.Println("\nEllipse: ", ellipse)

	for i := 0; i < 8; i++ {
		for j := 0; j < 8; j++ {
			// fmt.Println("(", i+1, ", ", 8-j, ") : single: ", singleMove.Get(j, i), "ellipse: ", ellipse.Get(j, i), "all: ", allMoves.Get(j, i))

			if singleMove.Get(j, i) != 0 && ellipse.Get(j, i) != 0 && allMoves.Get(j, i) == float64(next) {
				// fmt.Println("New Child Node: (", i+1, ", ", 8-j, ")")

				var newNode *node.Node
				newNode = new(node.Node)
				newNode.SetX(i + 1)
				newNode.SetY(8 - j)
				newNode.SetStep(next)

				baseNode.AddChild(newNode)
				result = append(result, newNode)
			}
		}
	}

	return result
}
开发者ID:Wmaxlees,项目名称:go-lg-chess,代码行数:55,代码来源:boards.go

示例2: GenerateMoveBoard

func GenerateMoveBoard(piece byte, x int, y int) *matrix.DenseMatrix {
	var singleMove *matrix.DenseMatrix
	var result *matrix.DenseMatrix

	// Start with the single move board
	switch piece {
	case Pawn:
		singleMove = singlePawnMove
	case Rook:
		singleMove = singleRookMove
	case Knight:
		singleMove = singleKnightMove
	case Bishop:
		singleMove = singleBishopMove
	case Queen:
		singleMove = singleQueenMove
	case King:
		singleMove = singleKingMove
	case Puppy:
		singleMove = singlePuppyMove
	}
	result = shiftMatrix(singleMove, x-8, y-8)

	for i := 0; i < 15; i++ {
		for j := 0; j < 15; j++ {
			if HoleBoard.Get(j, i) > float64(0) {
				result.Set(j, i, 500)
			}
		}
	}

	// fmt.Println(HoleBoard.String())

	// Get the secondary moves
	for n := 1; n < 20; n++ {
		// fmt.Println("Current State: \n", result.String())
		for i := 0; i < 15; i++ {
			for j := 0; j < 15; j++ {
				// Check if the current position needs to generate it's child moves
				if result.Get(i, j) == float64(n) {
					// Shift the single move matrix
					// fmt.Println("Generating moves from position (", j, ", ", i, ") as ", n)
					result = addMovesToBoard(result, shiftMatrix(singleMove, j-7, 15-(i+8)), n+1)
				}
			}
		}
	}

	// Remove the -1
	for i := 0; i < 15; i++ {
		for j := 0; j < 15; j++ {
			// Check if the current position needs to generate it's child moves
			if result.Get(i, j) == float64(-1) {
				result.Set(i, j, 0)
			}
		}
	}

	// fmt.Println(result.String())
	result = result.GetMatrix(7, 0, 8, 8)
	// for i := 0; i < 8; i++ {
	// 	for j := 0; j < 8; j++ {
	// 		if HoleBoard.Get(i, j) == 1 {
	// 			result.Set(j, i, 500)
	// 		}
	// 	}
	// }

	return result
}
开发者ID:Wmaxlees,项目名称:go-lg-chess,代码行数:70,代码来源:boards.go


注:本文中的github.com/skelterjohn/go/matrix.DenseMatrix.GetMatrix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。