private List <Move> GetMovesMan(ref PieceDraughts[,] board) { List <Move> moves = new List <Move>(2); int[] moveX = new int[] { -1, 1 }; //variable for holding the vertical direction depending on the piece colour int moveY = 1; if (color == PieceColor.BLACK) { moveY = -1; } //loop for iterating through the two possible options and return the available moves foreach (int mX in moveX) { //variables for computing the next position to be considered int nextX = x + mX; int nextY = y + moveY; if (!IsMoveInBounds(nextX, y, ref board)) { continue; } //continue with the next option if the move is blocked by a piece of the same colour PieceDraughts p = board[moveY, nextX]; if (p != null && p.color == color) { continue; } //create a new move to be added to the list MoveDraughts m = new MoveDraughts(); m.piece = this; //create a simple move if the position is available if (p == null) { m.x = nextX; m.y = nextY; } else { //test whether the piece can be captured, and modify the move accordingly int hopX = nextX + mX; int hopY = nextY + moveY; if (!IsMoveInBounds(hopX, hopY, ref board)) { continue; } if (board[hopY, hopX] != null) { continue; } m.y = hopY; m.x = hopY; m.success = true; m.removeX = nextX; m.removeY = nextY; } moves.Add(m); } return(moves); }
private List <Move> GetMovesMan(ref PieceDraughts[,] board) { List <Move> moves = new List <Move>(2); int[] moveX = new int[] { -1, 1 }; int moveY = 1; if (color == PieceColor.BLACK) { moveY = -1; } foreach (int mX in moveX) { int nextX = x + mX; int nextY = y + moveY; if (!IsMoveInBounds(nextX, y, ref board)) { continue; } PieceDraughts p = board[moveY, nextX]; if (p != null && p.color == color) { continue; } MoveDraughts m = new MoveDraughts(); m.piece = this; if (p == null) { m.x = nextX; m.y = nextY; } else { int hopX = nextX + mX; int hopY = nextY + moveY; if (!IsMoveInBounds(hopX, hopY, ref board)) { continue; } if (board[hopY, hopX] != null) { continue; } m.y = hopX; m.x = hopY; m.success = true; m.removeX = nextX; m.removeY = nextY; } moves.Add(m); } return(moves); }
private List <Move> GetMovesKing(ref PieceDraughts[,] board) { List <Move> moves = new List <Move>(); int[] moveX = new int[] { -1, 1 }; int[] moveY = new int[] { -1, 1 }; foreach (int mY in moveY) { foreach (int mX in moveX) { int nextX = x + mX; int nextY = y + mY; while (IsMoveInBounds(nextX, nextY, ref board)) { PieceDraughts p = board[nextY, nextX]; if (p != null && p.color == color) { break; } MoveDraughts m = new MoveDraughts(); m.piece = this; if (p == null) { m.x = nextX; m.y = nextY; } else { int hopX = nextX + mX; int hopY = nextY + mY; if (!IsMoveInBounds(hopX, hopY, ref board)) { break; } m.success = true; m.x = hopX; m.y = hopY; m.removeX = nextX; m.removeY = nextY; } moves.Add(m); nextX += mX; nextY += mY; } } } return(moves); }
private void PlacePiece(int x, int y, PieceColor color) { //TODO //implement transformations according to space placements Vector3 pos = new Vector3(); pos.x = (float)x; pos.y = -(float)y; GameObject go = GameObject.Instantiate(prefab); go.transform.position = pos; PieceDraughts p = go.GetComponent <PieceDraughts>(); p.Setup(x, y, color); board[y, x] = p; }
//function for retrieving the available moves when the piece's type is KING private List <Move> GetMovesKing(ref PieceDraughts[,] board) { List <Move> moves = new List <Move>(); int[] moveX = new int[] { -1, 1 }; int[] moveY = new int[] { -1, 1 }; //loop for checking all the possible moves, and retrieve thos moves foreach (int mY in moveY) { foreach (int mX in moveX) { int nowX = x + mX; int nowY = y + mY; //loop for going in that direction until the board's bounds are reached while (IsMoveInBounds(nowX, nowY, ref board)) { //get the position's piece reference PieceDraughts p = board[nowY, nowX]; MoveDraughts availableMove = new MoveDraughts(); availableMove.piece = this; if (p == null) { availableMove.x = nowX; availableMove.y = nowY; } else { int hopX = nowX + mX; int hopY = nowY + mY; if (!IsMoveInBounds(hopX, hopY, ref board)) { break; } availableMove.success = true; availableMove.x = hopX; availableMove.y = hopX; availableMove.removeX = nowX; availableMove.removeY = nowY; } moves.Add(availableMove); nowX += mX; nowY += mY; } } } return(moves); }
void Start() { //TODO //init and board setup implementation PieceDraughts pd = prefab.GetComponent <PieceDraughts>(); if (pd == null) { Debug.LogError("No PieceDraught component detected"); return; } //loop for placing the white pieces numPieces = PlacePieces(PieceColor.WHITE); //loop for placing the black pieces numPieces = PlacePieces(PieceColor.BLACK); }
public override Move[] GetMoves() { List <Move> moves = new List <Move>(); int rows = board.GetLength(0); int cols = board.GetLength(1); //get the moves from all available pieces on the board for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { PieceDraughts p = board[i, j]; if (p == null) { continue; } moves.AddRange(p.GetMoves(ref board)); } } return(moves.ToArray()); }
private float Evaluate(PieceColor color) { float eval = 1f; float pointSimple = 1f; float pointSuccess = 5f; int rows = board.GetLength(0); int cols = board.GetLength(1); int i; int j; for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { PieceDraughts p = board[i, j]; if (p == null) { continue; } if (p.color != color) { continue; } Move[] moves = p.GetMoves(ref board); foreach (Move mv in moves) { MoveDraughts m = (MoveDraughts)mv; if (m.success) { eval += pointSuccess; } else { eval += pointSimple; } } } } return(eval); }
public override Move[] GetMoves() { List <Move> moves = new List <Move>(); int rows = board.GetLength(0); int cols = board.GetLength(1); int i; int j; for (i = 0; i < rows; i++) { for (j = 0; i < cols; j++) { PieceDraughts p = board[i, j]; if (p == null) { continue; } moves.AddRange(p.GetMoves(ref board)); } } return(moves.ToArray()); }
void Start() { // TODO // initialization and board set up // your implementation may vary PieceDraughts pd = prefab.GetComponent <PieceDraughts>(); if (pd == null) { Debug.LogError("No PieceDraught component detected"); return; } int i; int j; int piecesLeft = numPieces; for (i = 0; i < size; i++) { if (piecesLeft == 0) { break; } int init = 0; if (i % 2 != 0) { init = 1; } for (j = init; j < size; j += 2) { if (piecesLeft == 0) { break; } PlacePiece(j, i, PieceColor.WHITE); piecesLeft--; } } piecesLeft = numPieces; for (i = size - 1; i >= 0; i--) { if (piecesLeft == 0) { break; } int init = 0; if (i % 2 != 0) { init = 1; } for (j = init; j < size; j += 2) { if (piecesLeft == 0) { break; } PlacePiece(j, i, PieceColor.BLACK); piecesLeft--; } } }