public override List<Tuple<MoveType, int, int>> GetMovableLoacation() { int h = Player == PlayerNo.Two ? -1 : 1; var list = new List<Tuple<MoveType, int, int>>(); list.Add(new Tuple<MoveType, int, int>(MoveType.NotExistAny, Left, Height+h)); list.Add(new Tuple<MoveType, int, int>(MoveType.ExistsEnemy, Left - 1, Height + h)); list.Add(new Tuple<MoveType, int, int>(MoveType.ExistsEnemy, Left + 1, Height + h)); return list; }
void addEnPassant(string colour, int row, int col, int rowOffset, int colOffset, List<int[]> enPassant, Piece[,] board) { int destinationRow = row + rowOffset; int destinationCol = col + colOffset; if (destinationRow >= 0 && destinationRow <= 7 && destinationCol >= 0 && destinationCol <= 7 && board[row, col + colOffset].EnPassant) { enPassant.Add(new int[] { destinationRow, destinationCol }); } }
internal static List<Peice> getPeices(Peice[,] board, PSide side) { List<Peice> sideList = new List<Peice>(); foreach (Peice peice in board) { if (peice != null && peice.MySide == side) { sideList.Add(peice); } } return sideList; }
public List<Tuple<int, int>> Rules(Piece piece, Gameboard gameboard) { if (piece.row == 0 || piece.row == 7) return new List<Tuple<int, int>>(); int max_row; int moving_factor; int step = 1; List<Tuple<int, int>> valid_destinations = new List<Tuple<int, int>>(); if (piece.team == (int)team.black) { max_row = 7; moving_factor = 1; if (piece.row == 1) ++step; } else { max_row = 0; moving_factor = -1; if (piece.row == 6) ++step; } for (int i = 1; i < step + 1; i++) { if (gameboard.getPiece(piece.row + (i * moving_factor), piece.column).empty && piece.row != max_row) { valid_destinations.Add(new Tuple<int, int>(piece.row + (i * moving_factor), piece.column)); } if (i == 1 && piece.column != 0 && gameboard.getPiece(piece.row + (i * moving_factor), piece.column - 1).team != piece.team && !gameboard.getPiece(piece.row + (i * moving_factor), piece.column - 1).empty) { valid_destinations.Add(new Tuple<int, int>(piece.row + (i * moving_factor), piece.column-1)); } if (i == 1 && piece.column != 7 && gameboard.getPiece(piece.row + (i * moving_factor), piece.column + 1).team != piece.team && !gameboard.getPiece(piece.row + (i * moving_factor), piece.column + 1).empty) { valid_destinations.Add(new Tuple<int, int>(piece.row + (i * moving_factor), piece.column+1)); } } return valid_destinations; }
public void Move(Gameboard gameboard, State currentState) { Rulebook rulebook = new Rulebook(); List<Tuple<Piece, Piece>> topValidMoves = new List<Tuple<Piece, Piece>>(); foreach(Piece piece in gameboard.getTeam(thisTeam)) { List<Tuple<int, int>> validDestinations = rulebook.getValidMoves(piece, gameboard); foreach (Tuple<int,int> coordinate in validDestinations) { if (validDestinations.Count() == 0) break; else if (topValidMoves.Count() == 0 || rewards[topValidMoves[0].Item2.type] == rewards[gameboard.getPiece(coordinate.Item1, coordinate.Item2).type]) topValidMoves.Add(new Tuple<Piece, Piece>(piece, gameboard.getPiece(coordinate.Item1, coordinate.Item2))); else if (rewards[topValidMoves[0].Item2.type] < rewards[gameboard.getPiece(coordinate.Item1, coordinate.Item2).type]) { topValidMoves.Clear(); topValidMoves.Add(new Tuple<Piece, Piece>(piece, gameboard.getPiece(coordinate.Item1, coordinate.Item2))); } } } if (topValidMoves.Count() != 0) { Random rand = new Random(); int index = rand.Next(topValidMoves.Count()); gameboard.Move(topValidMoves[index].Item1, topValidMoves[index].Item2); if (topValidMoves[index].Item1.type == (int)type.pawn && (topValidMoves[index].Item1.row == 0 || topValidMoves[index].Item1.row == 7)) { Piece bestPieceFromDead = new Piece(); foreach (Piece deadPiece in gameboard.getDead(thisTeam)) { if (rewards[deadPiece.type] > rewards[bestPieceFromDead.type]) bestPieceFromDead = deadPiece; } gameboard.tradePawn(topValidMoves[index].Item1, bestPieceFromDead); } //gameboard.checkChessMate(currentState.getWhosTurn()); } //currentState.swapTurn(); }
bool addThreatened(string colour, int row, int col, int rowOffset, int colOffset, List<int[]> threatened) { bool added = false; int destinationRow = row + rowOffset; int destinationCol = col + colOffset; if (uf.IsInBounds(destinationRow, destinationCol)) { threatened.Add(new int[] { destinationRow, destinationCol }); added = true; } return added; }
//doenst include king public List<Pair> GetBlackPosistions() { List<Pair> Positions = new List<Pair>(); foreach (ChessPiece piece in WhitePieces) { if (piece.InPlay) { Positions.Add(piece.Position); } } return Positions; }
public override List<Tuple<MoveType, int, int>> GetMovableLoacation() { var list = new List<Tuple<MoveType, int, int>>(); foreach (var l in new[] { -1, 0, 1 }) { foreach (var h in new[] { -1, 0, 1 }) { if (h != 0 || l != 0) list.Add(new Tuple<MoveType, int, int>(MoveType.Direction, Left + l, Height + h)); } } return list; }
public override List<Tuple<MoveType, int, int>> GetMovableLoacation() { var list = new List<Tuple<MoveType, int, int>>(); foreach (var l in new[] { -2,-1, 1,2 }) { foreach (var h in new[] { -2, -1, 1, 2 }) { if (l != h && h+l != 0) list.Add(new Tuple<MoveType, int, int>(MoveType.Normal, Left + l, Height + h)); } } return list; }
public override List<Tuple<MoveType, int, int>> GetMovableLoacation() { var list = new List<Tuple<MoveType, int, int>>(); foreach (int l in new[] { -1, 1 }) { foreach (int h in new[] { -1, 1 }) { list.Add(new Tuple<MoveType, int, int>(MoveType.Direction, l+this.Left, h+this.Height)); } } return list; }
bool addMoveable(int row, int col, int rowOffset, int colOffset, List<int[]> moveable, Piece[,] board) { bool added = false; int destinationRow = row + rowOffset; int destinationCol = col + colOffset; if (uf.IsInBounds(destinationRow, destinationCol)) { if (board[destinationRow, destinationCol].Colour != board[row, col].Colour && !cf.createCheck(row, col, destinationRow, destinationCol, board)) { moveable.Add(new int[] { destinationRow, destinationCol }); added = true; } } return added; }
public Gameboard(Gameboard originalGameboard) { for (int row = 0; row<8; ++row) { List<Piece> copyOfRow = new List<Piece>(); foreach (Piece piece in originalGameboard.getRow(row)) { Piece copyOfPiece = new Piece(piece); copyOfRow.Add(copyOfPiece); if (copyOfPiece.team == (int)team.black) this.blackTeam.Add(copyOfPiece); else if (copyOfPiece.team == (int)team.white) this.whiteTeam.Add(copyOfPiece); } this.gameboard.Add(copyOfRow); } }
public void highlightThreatened(Piece piece, int row, int col, List<int[]> threatened, List<int[]> enPassant, Piece[,] board, bool filtered = true) { switch (piece.PieceType) { case (Piece.Type.Pawn): pawnThreatenHighlight(piece, row, col, threatened, board, enPassant); break; case (Piece.Type.Rook): rookThreatenHighlight(piece.PieceColour, row, col, threatened, board); break; case (Piece.Type.Knight): knightThreatenHighlight(piece.PieceColour, row, col, threatened); break; case (Piece.Type.Bishop): bishopThreatenHighlight(piece.PieceColour, row, col, threatened, board); break; case (Piece.Type.Queen): queenThreatenHighlight(piece.PieceColour, row, col, threatened, board); break; case (Piece.Type.King): kingThreatenedHighlight(piece, row, col, threatened); break; default: throw new NotImplementedException("Attempted to move a non existent piece type"); } //filtered list only squares that can be moved to, ie. not pieces of the same colour, (need to add) or threatened pieces of the other colour for kings if (filtered) { List<int[]> toRemove = new List<int[]>(); foreach (int[] pair in threatened) if (board[row, col].PieceColour == board[pair[0], pair[1]].PieceColour) toRemove.Add(pair); //if (piece.Type == king) // foreach (int[] pair in threatened) // if (isThreatened(pair[0], pair[1], uf.OtherColour(piece.Colour), Playfield)) // toRemove.Add(pair); foreach (int[] pair in toRemove) threatened.Remove(pair); } }
List<int[]> getPossibleMoves(ChessBoard c, bool isWhite) { var retVal = new List<int[]>(); BitboardLayer[] dict = c.getDict(isWhite); BitboardLayer[] enemyDict = c.getDict(!isWhite); foreach (int i in dict[pieceIndex.ALL_LOCATIONS].getTrueIndicies()) { BitboardLayer pieceMoves = c.getValidMoves(isWhite, i); foreach (int j in pieceMoves.getTrueIndicies()) { retVal.Add(new int[] { i, j }); } } return retVal; }
void kingMoveHighlight(Piece piece, int row, int col, List<int[]> moveable, Piece[,] board) { //check down if (!cf.isThreatened(row + 1, col, uf.OtherColour(piece.Colour), board)) addMoveable(row, col, 1, 0, moveable, board); //check down right if (!cf.isThreatened(row + 1, col + 1, uf.OtherColour(piece.Colour), board)) addMoveable(row, col, 1, 1, moveable, board); //check right if (!cf.isThreatened(row, col + 1, uf.OtherColour(piece.Colour), board)) addMoveable(row, col, 0, 1, moveable, board); //check up right if (!cf.isThreatened(row - 1, col + 1, uf.OtherColour(piece.Colour), board)) addMoveable(row, col, -1, 1, moveable, board); //check up if (!cf.isThreatened(row - 1, col, uf.OtherColour(piece.Colour), board)) addMoveable(row, col, -1, 0, moveable, board); //check up left if (!cf.isThreatened(row - 1, col - 1, uf.OtherColour(piece.Colour), board)) addMoveable(row, col, -1, -1, moveable, board); //check left if (!cf.isThreatened(row, col - 1, uf.OtherColour(piece.Colour), board)) addMoveable(row, col, 0, -1, moveable, board); //check down left if (!cf.isThreatened(row + 1, col - 1, uf.OtherColour(piece.Colour), board)) addMoveable(row, col, 1, -1, moveable, board); #region castling //castling black left if (piece.Colour == black) { if (!piece.HasMoved && !board[0, 0].HasMoved && board[0, 0].Type == rook && !board[0, 1].Exists && !board[0, 2].Exists && !board[0, 3].Exists && !cf.isThreatened(0, 2, white, board) && !cf.isThreatened(0, 3, white, board) && !cf.isThreatened(0, 4, white, board)) { moveable.Add(new int[] { 0, 2 }); } //castling black right if (!piece.HasMoved && !board[0, 7].HasMoved && board[0, 0].Type == rook && !board[0, 5].Exists && !board[0, 6].Exists && !cf.isThreatened(0, 4, white, board) && !cf.isThreatened(0, 5, white, board) && !cf.isThreatened(0, 6, white, board)) { moveable.Add(new int[] { 0, 6 }); } } //castling white left if (piece.Colour == white) { if (!piece.HasMoved && !board[7, 0].HasMoved && board[0, 0].Type == rook && !board[7, 1].Exists && !board[7, 2].Exists && !board[7, 3].Exists && !cf.isThreatened(7, 2, black, board) && !cf.isThreatened(7, 3, black, board) && !cf.isThreatened(7, 4, black, board)) { moveable.Add(new int[] { 7, 2 }); } //castling white right if (!piece.HasMoved && !board[7, 7].HasMoved && board[0, 0].Type == rook && !board[7, 5].Exists && !board[7, 6].Exists && !cf.isThreatened(7, 4, black, board) && !cf.isThreatened(7, 5, black, board) && !cf.isThreatened(7, 6, black, board)) { moveable.Add(new int[] { 7, 6 }); } } #endregion }
private void PawnMoves(ref Piece pawn) { var moves = new List<Move>(); var direction = pawn.Color == PieceColor.White ? Direction.Up : Direction.Down; var squareOne = NextLegalSquare(pawn.Square, direction, pawn.Color); if (squareOne != null) { moves.Add(squareOne); if (!pawn.Moved) { var squareTwo = NextLegalSquare(squareOne, direction, pawn.Color); if (squareTwo != null) { moves.Add(squareTwo); } } } // En passant int rank = pawn.Color == PieceColor.White ? 5 : 4; if (pawn.Square.Rank == rank) { var left = NextSquare(pawn.Square, Direction.Left); if (left != null && left.Piece != null && left.Piece.Color != pawn.Color && left.Piece.Type == PieceType.Pawn) { var lastMove = Moves.Peek(); if (lastMove.Piece == left.Piece && lastMove.FirstMove) { moves.Add(leftAttack); } } var right = NextSquare(pawn.Square, Direction.Right); if (right != null && right.Piece != null && right.Piece.Color != pawn.Color && right.Piece.Type == PieceType.Pawn) { var lastMove = Moves.Peek(); if (lastMove.Piece == right.Piece && lastMove.FirstMove) { attacked.Add(rightAttack); } } } pawn.Moves = moves; }
private static IList<PiecePlacement> GetPieces(string placement) { var pieces = new List<PiecePlacement>(); int squareIdx = 0; foreach (var rank in placement.Split('/').Reverse()) { if (squareIdx % 8 != 0) throw new InvalidOperationException("Unexpected FEN format"); foreach (char c in rank) { if (c >= '1' && c <= '8') squareIdx += ((int)c - (int)'1' + 1); else pieces.Add(new PiecePlacement { PieceType = pieceNotation[char.ToLower(c)], Player = char.IsLower(c) ? PlayerColor.Black : PlayerColor.White, Square = (Square)squareIdx++ }); } } return pieces; }
private void KnightMoves(ref Piece knight) { var moves = new List<Move>(); var up = NextSquare(knight.Square, Direction.Up); var upLeft = NextLegalSquare(up, Direction.UpperLeft, knight.Color); if (upLeft != null) moves.Add(upLeft); var upRight = NextLegalSquare(up, Direction.UpperRight, knight.Color); if (upRight != null) moves.Add(upRight); var left = NextSquare(knight.Square, Direction.Left); var leftUp = NextLegalSquare(left, Direction.UpperLeft, knight.Color); if (leftUp != null) moves.Add(leftUp); var leftDown = NextLegalSquare(left, Direction.LowerLeft, knight.Color); if (leftDown != null) moves.Add(leftDown); var right = NextSquare(knight.Square, Direction.Right); var rightUp = NextLegalSquare(right, Direction.UpperRight, knight.Color); if (rightUp != null) moves.Add(rightUp); var rightDown = NextLegalSquare(right, Direction.LowerRight, knight.Color); if (rightDown != null) moves.Add(rightDown); var down = NextSquare(knight.Square, Direction.Down); var downLeft = NextLegalSquare(down, Direction.LowerLeft, knight.Color); if (downLeft != null) moves.Add(downLeft); var downRight = NextLegalSquare(down, Direction.LowerRight, knight.Color); if (downRight != null) moves.Add(downRight); knight.Moves = moves; }
private void PawnAttacked(ref Piece pawn) { var attacked = new List<Square>(); bool white = pawn.Color == PieceColor.White; var leftDirection = white ? Direction.UpperLeft : Direction.LowerLeft; var leftAttack = NextSquare(pawn.Square, leftDirection); if (leftAttack.Piece.Color != pawn.Color) { attacked.Add(leftAttack); } var rightDirection = white ? Direction.UpperRight : Direction.LowerRight; var rightAttack = NextSquare(pawn.Square, rightDirection); if (rightAttack.Piece.Color != pawn.Color) { attacked.Add(rightAttack); } pawn.Attacked = attacked; }
internal void setClicedKoma(int left, int height) { movableLoacation = new List<Tuple<int, int>>(); clickedKoma = this.getKoma(left, height); if (clickedKoma != null) { foreach (var locateInfo in this.getCanMove(clickedKoma.GetMovableLoacation(), clickedKoma)) { movableLoacation.Add(locateInfo); } } }
private void cleanUp() { Gameboard copyOfGameboard = new Gameboard(gameboard); Rulebook rulebook = new Rulebook(); List<Tuple<int, int>> copyOfValids = new List<Tuple<int, int>>(); bool foundIllegalMove = false; Piece originalCurrentPiece; int currentTeam = copyOfCurrentPiece.team; int opponentTeam = info.getOpponent(currentTeam); foreach (Tuple<int, int> validMove in validDestinations) // För varje möjligt drag för markerad Piece { copyOfGameboard = new Gameboard(gameboard); originalCurrentPiece = copyOfGameboard.getPiece(copyOfCurrentPiece.row, copyOfCurrentPiece.column); Piece destination = copyOfGameboard.getPiece(validMove.Item1, validMove.Item2); copyOfGameboard.Move(originalCurrentPiece, destination); // Gör temporärt move foundIllegalMove = false; foreach (Piece opponent in copyOfGameboard.getTeam(opponentTeam)) // För varje Piece i team OPPONENT { List<Tuple<int,int>> validDest = rulebook.getValidMoves(opponent, copyOfGameboard, false); // Hämta valid moves för Piece i OPPONENT (Utan hänsyn till möjliga drag som sätter kungen i schack..) foreach (Tuple<int,int> coordinate in validDest) // För varje möjligt drag för Piece i OPPONENT { if (copyOfGameboard.getPiece(coordinate.Item1, coordinate.Item2).type == (int)type.king) // Om Piece i OPPONENT kan ta kungen i CURRENT { foundIllegalMove = true; break; } if (foundIllegalMove) break; } if (foundIllegalMove) break; } if (!foundIllegalMove) copyOfValids.Add(new Tuple<int, int>(validMove.Item1, validMove.Item2)); copyOfGameboard.setPiece(originalCurrentPiece); copyOfGameboard.setPiece(destination); } validDestinations = copyOfValids; }
public int[] getMoveList(ChessBoard cb) { List<int> retVal = new List<int>(); var moveList = cb.getMoveList(); foreach (int[] i in moveList) { retVal.Add(i[0]); retVal.Add(i[1]); } return retVal.ToArray(); }
/** * Gets a list of all the Square numbers of Sqaures controlled by the enemy player */ private List<int> getEnemyControlledSquares(Position position) { List<int> controlledSquares = new List<int>(); for (int i = 0; i < 64; i++) { if (position.getPiece(i).Equals(PieceType.Empty)) continue; if ((Char.IsLower(position.getPiece(i).ToString()[0]) && position.whiteMove) | (Char.IsUpper(position.getPiece(i).ToString()[0]) && !position.whiteMove)) { controlledSquares.Add(i); } } return controlledSquares; }
/** * Colours the Pieces currently being defended IFF they are attackable */ internal void ColourOnlyDefendedPiecesUnderAttack() { List<int> enemyControlledSquares = getEnemyControlledSquares(position); List<int> attackedSquares = new List<int>(); // Remove the enemy pieces which are not under attack foreach (int i in enemyControlledSquares) { if (MoveGenerator.squareAttacked(position, i)) { attackedSquares.Add(i); } } if (attackedSquares.Count == 0) return; Position tempPos; foreach (int i in attackedSquares) { tempPos = FENConverter.convertFENToPosition(FENConverter.convertPositionToFEN(position)); tempPos.setPiece(i, ((position.whiteMove) ? PieceType.Q : PieceType.q)); tempPos.setWhiteMove(!position.whiteMove); if (MoveGenerator.squareAttacked(tempPos, i)) { board.ColourSquare(i, Chess.Properties.Settings.Default.DefendedPieces); } } }
void kingMoveHighlight(Piece piece, int row, int col, List<int[]> moveable, Piece[,] board) { //check down if (!cf.isThreatened(row + 1, col, uf.OtherColour(piece.PieceColour), board)) addMoveable(row, col, 1, 0, moveable, board); //check down right if (!cf.isThreatened(row + 1, col + 1, uf.OtherColour(piece.PieceColour), board)) addMoveable(row, col, 1, 1, moveable, board); //check right if (!cf.isThreatened(row, col + 1, uf.OtherColour(piece.PieceColour), board)) addMoveable(row, col, 0, 1, moveable, board); //check up right if (!cf.isThreatened(row - 1, col + 1, uf.OtherColour(piece.PieceColour), board)) addMoveable(row, col, -1, 1, moveable, board); //check up if (!cf.isThreatened(row - 1, col, uf.OtherColour(piece.PieceColour), board)) addMoveable(row, col, -1, 0, moveable, board); //check up left if (!cf.isThreatened(row - 1, col - 1, uf.OtherColour(piece.PieceColour), board)) addMoveable(row, col, -1, -1, moveable, board); //check left if (!cf.isThreatened(row, col - 1, uf.OtherColour(piece.PieceColour), board)) addMoveable(row, col, 0, -1, moveable, board); //check down left if (!cf.isThreatened(row + 1, col - 1, uf.OtherColour(piece.PieceColour), board)) addMoveable(row, col, 1, -1, moveable, board); #region castling //castling black left if (piece.PieceColour == Piece.Colour.Black) { //Check that the king hasn't moved if (!piece.HasMoved //and that the left rook hasn't moved && !board[Board.FirstRow, Board.FirstCol].HasMoved //and that it is a rook && board[Board.FirstRow, Board.FirstCol].PieceType == Piece.Type.Rook //and that there are no pieces between them && !board[Board.FirstRow, Board.FirstCol + 1].Exists && !board[Board.FirstRow, Board.FirstCol + 2].Exists && !board[Board.FirstRow, Board.FirstCol + 3].Exists //and that king doesn't move through tiles that are threatened by white && !cf.isThreatened(Board.FirstRow, Board.FirstCol + 2, Piece.Colour.White, board) && !cf.isThreatened(Board.FirstRow, Board.FirstCol + 3, Piece.Colour.White, board) && !cf.isThreatened(Board.FirstRow, Board.FirstCol + 4, Piece.Colour.White, board)) { moveable.Add(new int[] { Board.FirstRow, Board.FirstCol + 2 }); } //castling black right if (!piece.HasMoved && !board[Board.FirstRow, Board.LastCol].HasMoved && board[Board.FirstRow, Board.LastCol].PieceType == Piece.Type.Rook && !board[Board.FirstRow, Board.LastCol - 1].Exists && !board[Board.FirstRow, Board.LastCol - 2].Exists && !cf.isThreatened(Board.FirstRow, Board.LastCol - 3, Piece.Colour.White, board) && !cf.isThreatened(Board.FirstRow, Board.LastCol - 2, Piece.Colour.White, board) && !cf.isThreatened(Board.FirstRow, Board.LastCol - 1, Piece.Colour.White, board)) { moveable.Add(new int[] { Board.FirstRow, Board.LastCol - 1 }); } } //castling white left if (piece.PieceColour == Piece.Colour.White) { if (!piece.HasMoved && !board[Board.LastRow, Board.FirstCol].HasMoved && board[Board.LastRow, Board.FirstCol].PieceType == Piece.Type.Rook && !board[Board.LastRow, Board.FirstCol + 1].Exists && !board[Board.LastRow, Board.FirstCol + 2].Exists && !board[Board.LastRow, Board.FirstCol + 3].Exists && !cf.isThreatened(Board.LastRow, Board.FirstCol + 2, Piece.Colour.Black, board) && !cf.isThreatened(Board.LastRow, Board.FirstCol + 3, Piece.Colour.Black, board) && !cf.isThreatened(Board.LastRow, Board.FirstCol + 4, Piece.Colour.Black, board)) { moveable.Add(new int[] { Board.LastRow, Board.FirstCol + 2 }); } //castling white right if (!piece.HasMoved && !board[Board.LastRow, Board.LastCol].HasMoved && board[Board.LastRow, Board.LastCol].PieceType == Piece.Type.Rook && !board[Board.LastRow, Board.LastCol - 2].Exists && !board[Board.LastRow, Board.LastCol - 1].Exists && !cf.isThreatened(Board.LastRow, Board.LastCol - 3, Piece.Colour.Black, board) && !cf.isThreatened(Board.LastRow, Board.LastCol - 2, Piece.Colour.Black, board) && !cf.isThreatened(Board.LastRow, Board.LastCol - 1, Piece.Colour.Black, board)) { moveable.Add(new int[] { Board.LastRow, Board.LastCol - 1 }); } } #endregion }
private double evaluateChildren(MoveNode currentNode, int depth) { List<double> ratings = new List<double>(); foreach (MoveNode child in currentNode.Children) ratings.Add(child.Move.Rating); if (depth % 2 == 1) return ratings.Min(); else return ratings.Max(); }
private IEnumerable<Tuple< int, int>> getDirection( IEnumerable<Tuple<MoveType, int, int>> locationInfos ,KomaBase koma) { var directions = locationInfos.Where((location) => location.Item1 == MoveType.Direction); List<Tuple< int, int>> list = new List<Tuple< int, int>>(); foreach (var direction in directions) { int vL = direction.Item2 - koma.Left ; int vH =direction.Item3 - koma.Height ; for(int i =0;i<8;++i) { int left = i * vL + direction.Item2; int height = i * vH + direction.Item3; if (!isInBoard(left) || !isInBoard(height)) { break; } else if(this.existsKoma(left,height,playerNo)) { break; } else if (this.existsEnemy(left, height)) { list.Add(new Tuple<int, int>(left, height)); break; } else { list.Add(new Tuple<int, int>(left, height)); } } } return list; }
private void updatePieceList(List<Piece> pieces, Piece[,] board, string colour) { pieces.Clear(); for (int row = 0; row < 8; row++) for (int col = 0; col < 8; col++) { if (board[row, col].Colour == colour) pieces.Add(board[row, col]); } }
public List<int[]> sortAlphaBeta(ChessBoard cb, bool isWhite, List<int[]> possibleMoves) { List<int[]> retVal = new List<int[]>(); List<int> valueSet = new List<int>(); for (int i = 0; i < possibleMoves.Count; i++) { numIterations++; if (numIterations == 33000) { gui.addText("Found bug"); } int[] currMove = possibleMoves[i]; cb.movePiece(isWhite, currMove[0], currMove[1], true); valueSet.Add(Rating.rating(isWhite, cb, possibleMoves.Count, searchDepth)); cb.undoMove(isWhite); if (!matchesMoveList(cb)) { gui.addText("More errors!"); } } while (valueSet.Count > 0) { int index = indexOfMax(valueSet); retVal.Add(possibleMoves[index]); possibleMoves.RemoveAt(index); valueSet.RemoveAt(index); } return retVal; }
private IList<Square> NextLegalSquares(Square from, Direction direction, PieceColor pieceColor) { var nextLegalSquares = new List<Square>(); var current = from; while (true) { var next = NextLegalSquare(from, direction, pieceColor); if (next == null) break; if (next.Piece == null || next.Piece.Color != pieceColor) { nextLegalSquares.Add(next); current = next; } else break; } return nextLegalSquares; }