int CalculatePieceStrength(CheckersPiece piece) { int strength = 0; // Heuristic: Stronger simply because another piece is present strength += 1; // Rank-specific heuristics if (piece.Rank == CheckersRank.Pawn) { // Heuristic: stronger if in primary position on board if (piece.Direction == CheckersDirection.Up) { if (piece.Location.Y == CheckersGame.BoardBounds.Bottom) { strength += 1; } } else { if (piece.Location.Y == CheckersGame.BoardBounds.Top) { strength += 1; } } } else { // Heuristic: Stronger if king is on board strength += 19; } return(strength); }
public bool MakeMove(ref Board io_GameBoard, User i_RivalPlayer, string i_PositionFrom, string i_PositionTo) { bool isGameOver = false; if (GetMovesAndUpdate(io_GameBoard, i_RivalPlayer)) { playCapture(io_GameBoard, ref i_PositionFrom, ref i_PositionTo, i_RivalPlayer.Pieces); if (createCaptureMoveList(io_GameBoard, i_RivalPlayer).Count == 0) { m_CurrentCheckerPiece = null; } } else { // If the player still have moves to do. if (Moves.Keys.Count == 0 || m_CheckersPiece.Count == 0) { isGameOver = true; } else { playMove(io_GameBoard, ref i_PositionFrom, ref i_PositionTo); } } return(isGameOver); }
public static bool CanCaptureDown(Board i_GameBoard, CheckersPiece i_Current, List <CheckersPiece> i_RivalCheckersPiece, ref Dictionary <string, List <string> > io_CapturePositions) { bool canCaptureRight, canCaptureLeft; ushort rowIndex, colIndex; CheckersPiece rivalCheckerPieceDownRight, rivalCheckerPieceDownLeft; // Check if can capture down-right rival. rowIndex = (ushort)(i_Current.RowIndex + 1); colIndex = (ushort)(i_Current.ColIndex + 1); rivalCheckerPieceDownRight = FindCheckerPiece(rowIndex, colIndex, i_RivalCheckersPiece); canCaptureRight = tryInsertCapturePosition( i_GameBoard, i_Current, (ushort)(i_Current.RowIndex + 2), (ushort)(i_Current.ColIndex + 2), rivalCheckerPieceDownRight, ref io_CapturePositions); // Check if can capture down-left rival. rowIndex = (ushort)(i_Current.RowIndex + 1); colIndex = (ushort)(i_Current.ColIndex - 1); rivalCheckerPieceDownLeft = FindCheckerPiece(rowIndex, colIndex, i_RivalCheckersPiece); canCaptureLeft = tryInsertCapturePosition( i_GameBoard, i_Current, (ushort)(i_Current.RowIndex + 2), (ushort)(i_Current.ColIndex - 2), rivalCheckerPieceDownLeft, ref io_CapturePositions); return(canCaptureLeft || canCaptureRight); }
int CalculatePieceStrength(CheckersPiece piece) { int strength = 0; // Heuristic: Stronger simply because another piece is present strength += 1; // Rank-specific heuristics if(piece.Rank == CheckersRank.Pawn) { // Heuristic: stronger if in primary position on board if(piece.Direction == CheckersDirection.Up) { if(piece.Location.Y == CheckersGame.BoardBounds.Bottom) strength += 1; } else { if(piece.Location.Y == CheckersGame.BoardBounds.Top) strength += 1; } } else { // Heuristic: Stronger if king is on board strength += 19; } return strength; }
private bool isValidCapture(Board i_GameBoard, string io_PositionFrom, string io_PositionTo, ref CheckersPiece io_CurrentChecker, List <CheckersPiece> i_RivalPieces, ref CheckersPiece io_RivalChecker) { bool isValid = false; ushort rowIndex, colIndex; foreach (string positionFrom in Moves.Keys) { if (io_PositionFrom == positionFrom) { if (isPositionInList(io_PositionTo, Moves[positionFrom])) { rowIndex = i_GameBoard.GetIndexInBoard(ref io_PositionFrom, out colIndex); io_CurrentChecker = CaptureUtils.FindCheckerPiece(rowIndex, colIndex, Pieces); colIndex += (ushort)(io_PositionTo[k_ColIndex] - io_PositionFrom[k_ColIndex]); rowIndex += (ushort)(io_PositionTo[k_RowIndex] - io_PositionFrom[k_RowIndex]); getRivalPosition(ref rowIndex, ref colIndex, io_PositionTo[k_RowIndex] < io_PositionFrom[k_RowIndex], io_PositionTo[k_ColIndex] < io_PositionFrom[k_ColIndex]); io_RivalChecker = CaptureUtils.FindCheckerPiece((ushort)rowIndex, (ushort)colIndex, i_RivalPieces); isValid = true; break; } } } return(isValid); }
public void MakeCapture(Board i_GameBoard, ref CheckersPiece io_CurrentCheckerPiece, ref string io_PositionTo, ref CheckersPiece io_RivalCheckerPiece) { CaptureUtils.CaptureRivalCheckerPiece(i_GameBoard, ref io_CurrentCheckerPiece, io_PositionTo, ref io_RivalCheckerPiece); m_CurrentCheckerPiece = io_CurrentCheckerPiece; }
private static bool isCorrectMoveKingDownWay(CheckersPiece i_CurrentCheckerPiece, ushort i_BoardSize, string i_PositionTo) { return((i_CurrentCheckerPiece.ColIndex + 1 == i_PositionTo[k_ColIndex] - 'A' && i_CurrentCheckerPiece.RowIndex + 1 == i_PositionTo[k_RowIndex] - 'a') || (i_CurrentCheckerPiece.ColIndex - 1 == i_PositionTo[k_ColIndex] - 'A' && i_CurrentCheckerPiece.RowIndex + 1 == i_PositionTo[k_RowIndex] - 'a')); }
private static bool isAvailableCellDownRightWay(Board i_GameBoard, CheckersPiece i_CurrentCheckerPiece) { ushort newRowIndex = (ushort)(i_CurrentCheckerPiece.RowIndex + 1); ushort newColRightIndex = (ushort)(i_CurrentCheckerPiece.ColIndex + 1); return(i_GameBoard.IsCheckerAvailable(newRowIndex, newColRightIndex)); }
public MoveResult(MoveType type, CheckersPiece piece, int nx, int ny) { Type = type; OriginalPieceLocation = new Location(piece.X, piece.Y); FinalPieceLocation = new Location(nx, ny); JumpResults = new List<JumpResult>(); }
private static void checkCorrectMoveWayDown(CheckersPiece i_CurrentCheckerPiece, ref string io_PositionFrom, ref string io_PositionTo, string i_Name) { while (!isCorrectMoveDownWay(i_CurrentCheckerPiece, io_PositionTo)) { Console.WriteLine("The request position to move is not legal. You can make only diagonal move."); UserTurnConversation(i_Name, ref io_PositionFrom, ref io_PositionTo); } }
private void playerMustMoveValid(Board i_GameBoard, ref string io_PositionFrom, ref string io_PositionTo, ref CheckersPiece io_CurrentChecker) { while (!isValidMove(i_GameBoard, io_PositionFrom, io_PositionTo, ref io_CurrentChecker)) { Console.WriteLine("Invalid move. player must move with to free positions."); //string move = UserInterface.GetValidMove(i_GameBoard); // Validation.ParsePositions(move, ref io_PositionFrom, ref io_PositionTo); Validation.UserTurnConversation(Name, ref io_PositionFrom, ref io_PositionTo); } }
public void MakeUserMove(ref Board io_GameBoard, ref CheckersPiece io_CurrentChecker, string i_PositionFrom, string i_PositionTo) { if (!io_CurrentChecker.IsKing) { MoveUtils.MoveTool(ref io_GameBoard, ref io_CurrentChecker, i_PositionTo); MakeToolAKing(io_GameBoard, ref io_CurrentChecker); } else { MoveUtils.MoveTool(ref io_GameBoard, ref io_CurrentChecker, i_PositionTo); } }
// Constructors: public User(string i_Name, ePlayerType i_PlayerNumber, bool i_IsComputer) { m_Name = i_Name; m_Score = 0; m_CheckersPiece = null; m_PlayerNumber = i_PlayerNumber; m_CheckerPieceKind = i_PlayerNumber == ePlayerType.MainPlayer ? CheckersPiece.ePieceKind.MainPlayerTool : CheckersPiece.ePieceKind.SecondPlayerTool; m_Moves = null; m_CurrentCheckerPiece = null; m_IsComputer = i_IsComputer; }
internal void UpdatePieceInBoard(CheckersPlayer i_Player, int i_CurrentRow, int i_CurrentColumn, int i_TargetRow, int i_TargetColumn) { CheckersPiece pieceToMove = r_CheckersBoard[i_CurrentRow, i_CurrentColumn].Piece; r_CheckersBoard[i_TargetRow, i_TargetColumn].Piece = pieceToMove; r_CheckersBoard[i_CurrentRow, i_CurrentColumn].Piece = null; r_CheckersBoard[i_TargetRow, i_TargetColumn].Piece.Location = new int[2] { i_TargetRow, i_TargetColumn }; changePieceToKingIfNeeded(i_Player, pieceToMove, i_TargetRow); }
private void playerMustCapture(Board i_GameBoard, ref string io_PositionFrom, ref string io_PositionTo, ref CheckersPiece io_CurrentChecker, List <CheckersPiece> i_RivalPieces, ref CheckersPiece io_RivalChecker) { while (!isValidCapture(i_GameBoard, io_PositionFrom, io_PositionTo, ref io_CurrentChecker, i_RivalPieces, ref io_RivalChecker)) { Console.WriteLine("Invalid move. player must capture."); //string move = UserInterface.GetValidMove(i_GameBoard); //Validation.ParsePositions(move, ref io_PositionFrom, ref io_PositionTo); Validation.UserTurnConversation(Name, ref io_PositionFrom, ref io_PositionTo); } }
private void computerMustCapture(Board i_GameBoard, ref string io_PositionFrom, ref string io_PositionTo, ref CheckersPiece io_CurrentChecker, List <CheckersPiece> i_RivalPieces, ref CheckersPiece io_RivalChecker) { while (!isValidCapture(i_GameBoard, io_PositionFrom, io_PositionTo, ref io_CurrentChecker, i_RivalPieces, ref io_RivalChecker)) { int randomKey = new Random().Next(Moves.Keys.Count); io_PositionFrom = getRandomKey(randomKey); int randomValue = new Random().Next(Moves[io_PositionFrom].Count); io_PositionTo = Moves[io_PositionFrom][randomValue]; } }
private void playMove(Board io_GameBoard, ref string io_PositionFrom, ref string io_PositionTo) { CheckersPiece checkerPieceToMove = null; if (!IsComputer) { playerMustMoveValid(io_GameBoard, ref io_PositionFrom, ref io_PositionTo, ref checkerPieceToMove); MakeUserMove(ref io_GameBoard, ref checkerPieceToMove, io_PositionFrom, io_PositionTo); } else { MakeComputerMove(ref io_GameBoard, ref checkerPieceToMove); } }
// Computer Player Methods: public void MakeComputerMove(ref Board io_GameBoard, ref CheckersPiece io_CurrentChecker) { string[] positions = getRandomMove(io_GameBoard, ref io_CurrentChecker); if (!io_CurrentChecker.IsKing) { MoveUtils.MoveTool(ref io_GameBoard, ref io_CurrentChecker, positions[1]); MakeToolAKing(io_GameBoard, ref io_CurrentChecker); } else { MoveUtils.MoveTool(ref io_GameBoard, ref io_CurrentChecker, positions[1]); } }
internal void RemoveOpponentPiece(int i_CurrentRow, int i_CurrentColumn, int i_TargetRow, int i_TargetColumn, CheckersPlayer i_Opponent) { int PorgressRowDirection = (i_TargetRow - i_CurrentRow) / 2; int PorgressColumnDirection = (i_TargetColumn - i_CurrentColumn) / 2; int PieceToDeleteRowLocation = i_CurrentRow + PorgressRowDirection; int PieceToDeleteColumnLocation = i_CurrentColumn + PorgressColumnDirection; CheckersPiece eatenPiece = r_CheckersBoard[PieceToDeleteRowLocation, PieceToDeleteColumnLocation].Piece; i_Opponent.PlayerPieces.Remove(eatenPiece); r_CheckersBoard[PieceToDeleteRowLocation, PieceToDeleteColumnLocation].Piece = null; }
private string[] getRandomMove(Board i_GameBoard, ref CheckersPiece io_CurrentChecker) { int keyIndex = new Random().Next(Moves.Keys.Count); string[] positions = new string[2]; while (!isCheckerFoundAndUpdate(i_GameBoard, keyIndex, out positions[0], out positions[1], ref io_CurrentChecker)) { keyIndex = new Random().Next(Moves.Keys.Count); } return(positions); }
public static void CaptureRivalCheckerPiece(Board i_GameBoard, ref CheckersPiece io_CurrentCheckerPiece, string i_PositionTo, ref CheckersPiece io_RivalCheckerPiece) { ushort nextColIndex; ushort nextRowIndex = i_GameBoard.GetIndexInBoard(ref i_PositionTo, out nextColIndex); // Update board after eating, and move the current checker to his next place. i_GameBoard.UpdateAfterEating(io_CurrentCheckerPiece.RowIndex, io_CurrentCheckerPiece.ColIndex, nextRowIndex, nextColIndex, io_RivalCheckerPiece.RowIndex, io_RivalCheckerPiece.ColIndex); // Update current checker position. io_CurrentCheckerPiece.ChangePosition(nextRowIndex, nextColIndex); // Update rival's checker status (dead). io_RivalCheckerPiece.Die(); }
private CheckersPiece updateCurrentCheckerPiece(ushort i_RowIndex, ushort i_ColIndex) { CheckersPiece foundCheckerPiece = null; foreach (CheckersPiece checkerPiece in m_CheckersPiece) { if (CaptureUtils.IsSamePosition(checkerPiece, i_RowIndex, i_ColIndex)) { foundCheckerPiece = checkerPiece; break; } } return(foundCheckerPiece); }
public static CheckersPiece FindCheckerPiece(ushort i_RowIndex, ushort i_ColIndex, List <CheckersPiece> i_RivalChckersPiece) { CheckersPiece currentCheckerPiece = null; foreach (CheckersPiece piece in i_RivalChckersPiece) { if (IsSamePosition(piece, i_RowIndex, i_ColIndex)) { currentCheckerPiece = piece; break; } } return(currentCheckerPiece); }
private static bool tryInsertCapturePosition( Board i_GameBoard, CheckersPiece i_CurrentChecker, ushort i_RowIndex, ushort i_ColIndex, CheckersPiece i_RivalChecker, ref Dictionary <string, List <string> > io_CapturePositions) { bool canInsert = false; if (i_RivalChecker != null && isAvailableCaptureCell(i_GameBoard, i_RowIndex, i_ColIndex)) { string captureIndex = MoveUtils.GetStringIndexes(i_RowIndex, i_ColIndex); MoveUtils.AddToDict(ref io_CapturePositions, i_CurrentChecker, captureIndex); canInsert = true; } return(canInsert); }
public override void Draw(Board board, List<CheckersPiece> playerOnePieces, List<CheckersPiece> playerTwoPieces, List<MoveResult> availableMoves, CheckersPiece selectedPiece = null) { for (var i = 0; i < board.Width; i++) { for (var j = 0; j < board.Height; j++) { var tileTexture = board.GetTile(i, j).Color == TileColor.Black ? _blackTile : _whiteTile; _spriteBatch.Draw(tileTexture, new Rectangle(i*TileSize, j*TileSize, TileSize, TileSize), Color.White); } } DrawAvailableMoves(availableMoves); DrawPieces(_blackPiece, playerOnePieces, selectedPiece); DrawPieces(_redPiece, playerTwoPieces, selectedPiece); }
private void changePieceToKingIfNeeded(CheckersPlayer i_Player, CheckersPiece i_Piece, int i_TargetRow) { if (i_TargetRow == 0) { if (i_Player.PawnType == CheckersPiece.ePieceType.X) { i_Piece.PieceType = CheckersPiece.ePieceType.K; } } else if (i_TargetRow == r_BoardSize - 1) { if (i_Player.PawnType == CheckersPiece.ePieceType.O) { i_Piece.PieceType = CheckersPiece.ePieceType.U; } } }
private double GetPiecePoints(CheckersBoard board,CheckersPiece piece, PieceColor playerColor) { int area = 1; if (piece.X <= Area2Width || piece.X >= board.Width - Area2Width || piece.Y <= Area2Width || piece.Y >= board.Height - Area2Width) area = 2; double points = 0; if (piece is Pawn) { points = area == 2 ? _pawnStrengthArea2 : _pawnStrengthArea1; } else if (piece is Queen) { points = area == 2 ? _queenStrengthArea2 : _queenStrengthArea1; } return points * (piece.Color == playerColor ? 1 : -1); }
// Move Tools Methods: public static void MoveTool(ref Board io_GameBoard, ref CheckersPiece io_CurrentChecker, string i_PositionTo) { ushort nextRowIndex = (ushort)(i_PositionTo[k_RowIndex] - 'a'); ushort nextColIndex = (ushort)(i_PositionTo[k_ColIndex] - 'A'); // If there is not(!) a rival checker piece in the way. // Check valid move - include: inborder, valid input, is empty cell. // Validation.CheckValidMoveRegularTool(io_GameBoard, i_CurrentPlayer, io_CurrentChecker, ref i_PositionFrom, ref i_PositionTo); // Update board - new tool position. io_GameBoard.UpdateBoardAccordingToPlayersMove( io_CurrentChecker.RowIndex, io_CurrentChecker.ColIndex, nextRowIndex, nextColIndex); io_CurrentChecker.ChangePosition(nextRowIndex, nextColIndex); }
private static void getUpCellsPosition(ref Dictionary <string, List <string> > io_OptionsMove, Board i_GameBoard, CheckersPiece i_CurrentCheckerPiece) { ushort newRowIndex = (ushort)(i_CurrentCheckerPiece.RowIndex - 1); ushort newColRightIndex = (ushort)(i_CurrentCheckerPiece.ColIndex + 1); ushort newColLeftIndex = (ushort)(i_CurrentCheckerPiece.ColIndex - 1); string positionRightStr = GetStringIndexes(newRowIndex, newColRightIndex); string positionLeftStr = GetStringIndexes(newRowIndex, newColLeftIndex); if (isAvailableCellUpRightWay(i_GameBoard, i_CurrentCheckerPiece)) { AddToDict(ref io_OptionsMove, i_CurrentCheckerPiece, positionRightStr); } if (isAvailableCellUpLeftWay(i_GameBoard, i_CurrentCheckerPiece)) { AddToDict(ref io_OptionsMove, i_CurrentCheckerPiece, positionLeftStr); } }
private void playCapture(Board io_GameBoard, ref string io_PositionFrom, ref string io_PositionTo, List <CheckersPiece> i_RivalPlayerPieces) { CheckersPiece checkerPieceToMove = null; CheckersPiece rivalCheckerPiece = null; if (!IsComputer) { playerMustCapture(io_GameBoard, ref io_PositionFrom, ref io_PositionTo, ref checkerPieceToMove, i_RivalPlayerPieces, ref rivalCheckerPiece); } else { computerMustCapture(io_GameBoard, ref io_PositionFrom, ref io_PositionTo, ref checkerPieceToMove, i_RivalPlayerPieces, ref rivalCheckerPiece); } // Checks if there's an optional capture, and updating the data structure. MakeCapture(io_GameBoard, ref checkerPieceToMove, ref io_PositionTo, ref rivalCheckerPiece); checkerPieceToMove.GotToOtherSideOfBoard(ref io_GameBoard); // Remove checker piece from rival's soldiers. i_RivalPlayerPieces.Remove(rivalCheckerPiece); }
public void KillPiece(CheckersPiece killedPiece, int timestamp) { killedPiece.InPlay = false; killedPiece.Timestamp = timestamp; var listToKill = (killedPiece.Color == PieceColor.Black ? AlivePlayerOnePieces : AlivePlayerTwoPieces); var listToAdd = (killedPiece.Color == PieceColor.Black ? CapturedPlayerOnePieces : CapturedPlayerTwoPieces); for (var i = 0; i < listToKill.Count; i++) { var p = listToKill[i]; if (p.X == killedPiece.X && p.Y == killedPiece.Y) { listToKill.RemoveAt(i); break; } } listToAdd.Add(killedPiece); }
private static bool isCorrectMoveKingWay(CheckersPiece i_CurrentCheckerPiece, ushort i_BoardSize, string i_PositionTo) { return(isCorrectMoveKingDownWay(i_CurrentCheckerPiece, i_BoardSize, i_PositionTo) && isCorrectMoveKingUpWay(i_CurrentCheckerPiece, i_BoardSize, i_PositionTo)); }
public static void AddToDict(ref Dictionary <string, List <string> > io_Options, CheckersPiece i_CurrentChecker, string i_OptionPosition) { string currentPosition = GetStringIndexes(i_CurrentChecker.RowIndex, i_CurrentChecker.ColIndex); if (!io_Options.ContainsKey(currentPosition)) { io_Options.Add(currentPosition, new List <string>()); } io_Options[currentPosition].Add(i_OptionPosition); }
// Valid Move Methods: public static void CheckValidMoveRegularTool(Board i_GameBoard, User i_CurrentPlayer, CheckersPiece i_CurrentCheckerPiece, ref string io_PositionFrom, ref string io_PositionTo) { while (!i_GameBoard.IsCheckerAvailable((ushort)(io_PositionTo[k_RowIndex] - 'a'), (ushort)(io_PositionTo[k_ColIndex] - 'A'))) { Console.WriteLine("The request position to move is not legal. Please enter position, which the cell is free to move."); UserTurnConversation(i_CurrentPlayer.Name, ref io_PositionFrom, ref io_PositionTo); } if (i_CurrentPlayer.CheckerKind == CheckersPiece.ePieceKind.SecondPlayerKing /*CheckersPiece.ePieceKind.O*/) { // The current player can move only down and in diagonal move. checkCorrectMoveWayDown(i_CurrentCheckerPiece, ref io_PositionFrom, ref io_PositionTo, i_CurrentPlayer.Name); } else // If the current player has tools from 'X' kind. { // The current player can move only up and in diagonal move. checkCorrectMoveWayUp(i_CurrentCheckerPiece, ref io_PositionFrom, ref io_PositionTo, i_CurrentPlayer.Name); } }
private void SetSelectedPiece(CheckersGameDriver gameDriver, CheckersPiece piece) { _xnaCheckersDriver.CurrentGameState = GameState.MovingPiece; CurrentSelectedPiece = piece; _allAvailableMoves = gameDriver.Board.GetAllAvailableMoves(Color); _selectedAvailableMoves = gameDriver.Board.GetAvailableMovesForPiece(piece, false); }
// returns the possible moves for a given piece, if jumpsOnly is set, then only jumps will be considered public List<MoveResult> GetAvailableMovesForPiece(CheckersPiece piece, bool jumpsOnly) { var moveResults = new List<MoveResult>(); var jumpsAvailable = GetAvailableJumps(piece.X, piece.Y, piece.Color); if (jumpsAvailable.Count > 0 || jumpsOnly) { for (var i = 0; i < jumpsAvailable.Count; i++) { var jump = jumpsAvailable[i]; var mr = new MoveResult(MoveType.Jump, piece, jump.FinalLocation.X, jump.FinalLocation.Y) {JumpResults = jump.LocationsJumped}; moveResults.Add(mr); } return moveResults; //user must make a jummp } //possible forward moves must be considered too var possibleEndValues = new List<Location> { new Location(piece.X - 1, piece.Y + (int)piece.Forward), new Location(piece.X + 1, piece.Y + (int)piece.Forward) }; for (var i = possibleEndValues.Count - 1; i >= 0; i--) { var p = possibleEndValues[i]; //remove invalid final locations (piece is there or the location is invalid) if (!TileBoard.IsValidLocation(p) || Pieces.GetPieceAtPosition(p) != null) possibleEndValues.RemoveAt(i); } for (var i = 0; i < possibleEndValues.Count; i++) { var possibleEndValue = possibleEndValues[i]; moveResults.Add(new MoveResult(MoveType.Forward, piece, possibleEndValue.X, possibleEndValue.Y)); } return moveResults; }
private void NewMove(CheckersPiece piece, BoardPosition position) { _moves.Clear(); _moves.Add(position); _posiblemoves = piece.PossibleMoves; _currentPath = new List<BoardPosition>(); _currentPath.Add(new BoardPosition(piece.X, piece.Y)); _boardDrawer.ClearSelection(); _boardDrawer.Selected[piece.X, piece.Y] = true; }
public void RevivePiece(CheckersPiece ressedPiece) { ressedPiece.InPlay = true; ressedPiece.Timestamp = 0; var listToKill = (ressedPiece.Color == PieceColor.Black ? CapturedPlayerOnePieces : CapturedPlayerTwoPieces); var listToAdd = (ressedPiece.Color == PieceColor.Black ? AlivePlayerOnePieces : AlivePlayerTwoPieces); for (var i = 0; i < listToKill.Count; i++) { var p = listToKill[i]; if (p.X == ressedPiece.X && p.Y == ressedPiece.Y) { listToKill.RemoveAt(i); break; } } listToAdd.Add(ressedPiece); }
private void DrawPieces(Texture2D pieceTexture, List<CheckersPiece> pieces, CheckersPiece selectedPiece) { for (var i = 0; i < pieces.Count; i++) { var piece = pieces[i]; var rectToDrawIn = new Rectangle(piece.X*TileSize, piece.Y*TileSize, TileSize, TileSize); if(piece.Equals(selectedPiece)) { _spriteBatch.Draw(_selectedGlow, new Vector2(rectToDrawIn.Center.X, rectToDrawIn.Center.Y), null, Color.White, 0f, new Vector2(48, 48), 1f, SpriteEffects.None, 0); } _spriteBatch.Draw(pieceTexture, rectToDrawIn, Color.White); } }
public override void Draw(Board board, List<CheckersPiece> playerOnePieces, List<CheckersPiece> playerTwoPieces, List<MoveResult> availableMoves, CheckersPiece selectedPiece = null) { Console.Clear(); //if you want to write to console, fill the rest of this function out }
public abstract void Draw(Board board, List<CheckersPiece> playerOnePieces, List<CheckersPiece> playerTwoPieces, List<MoveResult> availableMoves, CheckersPiece selectedPiece = null);
public static bool IsSamePosition(CheckersPiece i_ChckerPiece, ushort i_RowIndex, ushort i_ColIndex) { return(i_ChckerPiece.ColIndex == i_ColIndex && i_ChckerPiece.RowIndex == i_RowIndex); }
public virtual Color GetPieceColor(CheckersPiece piece) { if (piece is Pawn) return piece.Color == PieceColor.White ? Color.LightBlue : Color.MediumPurple; else if (piece is Queen) return piece.Color == PieceColor.White ? Color.Blue : Color.Purple; else return Color.Empty; }
public InvalidMoveException(CheckersPiece piece, int newX, int newY) { MovingPiece = piece; AttemptedLocation = new Location(newX, newY); }