public void RemoveCapturedPieces() { foreach (Int32 pieceKey in DelayRemovePiecesKeys) { if (PawnsKeys.Contains(pieceKey)) { PawnsKeys.Remove(pieceKey); } if (MovingPieces.ContainsKey(pieceKey)) { MovingPieces.Remove(pieceKey); } AllPieces.Remove(pieceKey); } DelayRemovePiecesKeys.Clear(); }
public void HandleMove(int newRow, int newCol) { //Remove the jumped piece if (MustJump[SelectedPiece.Color]) { foreach (var piece in AllPieces.Where(piece => piece.Status == CheckerPieceStatus.Alive)) { if (piece.Row == (newRow + SelectedPiece.Row) / 2 && piece.Col == (newCol + SelectedPiece.Col) / 2) { piece.Kill(DateTime.Now); //AllPieces.RemoveAt(i); break; } } JumpMade = SelectedPiece; } //Change the piece's position; SelectedPiece.Row = newRow; SelectedPiece.Col = newCol; }
public byte[,] GetField() { byte[,] ret = new byte[8, 8]; for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { ret[x, y] = (byte)(AllPieces.Get(x, y) ? 0 : 16); ret[x, y] |= (byte)(white.Get(x, y) ? 0 : 8); ret[x, y] |= (byte)(pawn.Get(x, y) ? 0 : 0); ret[x, y] |= (byte)(knight.Get(x, y) ? 1 : 0); ret[x, y] |= (byte)(bishop.Get(x, y) ? 2 : 0); ret[x, y] |= (byte)(rook.Get(x, y) ? 3 : 0); ret[x, y] |= (byte)(queen.Get(x, y) ? 4 : 0); ret[x, y] |= (byte)(king.Get(x, y) ? 5 : 0); } } return(ret); }
//checks the status of a checkerboard state, 0 = draw, -1 = lose, 1 = win, 2 = continue public CheckerStatus GetStatus(int playerColor) { //Game is a Draw if (MovablePieces[playerColor].Count == 0) { return(CheckerStatus.Lose); } //Count the number of pieces of a color int numWhite = AllPieces.Count(piece => piece.Status == CheckerPieceStatus.Alive && piece.Color == 0); //Win/Lose if (numWhite == AllPieces.Count(piece => piece.Status == CheckerPieceStatus.Alive)) { return(playerColor == 0 ? CheckerStatus.Win : CheckerStatus.Lose); } if (numWhite == 0) { return(playerColor == 1 ? CheckerStatus.Win : CheckerStatus.Lose); } return(CheckerStatus.Continue); }
public MainWindowViewModel() { AllPieces = Pieces.GetValues(); SelectedPiece = AllPieces.First(); }
public override int GetHashCode() { return(AllPieces.GetHashCode()); }
//private voids public void CalcSoftMoves() { softMoves = new List <Move>(); movesProved = false; BitBoard active; //Pawns PawnMoves(ref softMoves, pawn & (player ? black : white)); //Knight TryMoveOrKill(ref softMoves, knight & (player ? black : white), 1, 2, Category.Knight); TryMoveOrKill(ref softMoves, knight & (player ? black : white), -1, 2, Category.Knight); TryMoveOrKill(ref softMoves, knight & (player ? black : white), 1, -2, Category.Knight); TryMoveOrKill(ref softMoves, knight & (player ? black : white), -1, -2, Category.Knight); TryMoveOrKill(ref softMoves, knight & (player ? black : white), 2, 1, Category.Knight); TryMoveOrKill(ref softMoves, knight & (player ? black : white), -2, 1, Category.Knight); TryMoveOrKill(ref softMoves, knight & (player ? black : white), 2, -1, Category.Knight); TryMoveOrKill(ref softMoves, knight & (player ? black : white), -2, -1, Category.Knight); //Bishop active = bishop & (player ? black : white); for (int i = 1; i < 8 && !active.Empty; i++) { TryMoveOrKill(ref softMoves, ref active, i, i, Category.Bishop); } active = bishop & (player ? black : white); for (int i = 1; i < 8 && !active.Empty; i++) { TryMoveOrKill(ref softMoves, ref active, -i, i, Category.Bishop); } active = bishop & (player ? black : white); for (int i = 1; i < 8 && !active.Empty; i++) { TryMoveOrKill(ref softMoves, ref active, i, -i, Category.Bishop); } active = bishop & (player ? black : white); for (int i = 1; i < 8 && !active.Empty; i++) { TryMoveOrKill(ref softMoves, ref active, -i, -i, Category.Bishop); } //Rook active = rook & (player ? black : white); //as ulong as there are active pieces test further for (int i = 1; i < 8 && !active.Empty; i++) { TryMoveOrKill(ref softMoves, ref active, i, 0, Category.Rook); } active = rook & (player ? black : white); for (int i = 1; i < 8 && !active.Empty; i++) { TryMoveOrKill(ref softMoves, ref active, -i, 0, Category.Rook); } active = rook & (player ? black : white); for (int i = 1; i < 8 && !active.Empty; i++) { TryMoveOrKill(ref softMoves, ref active, 0, i, Category.Rook); } active = rook & (player ? black : white); for (int i = 1; i < 8 && !active.Empty; i++) { TryMoveOrKill(ref softMoves, ref active, 0, -i, Category.Rook); } //Queen active = queen & (player ? black : white); for (int i = 1; i < 8 && !active.Empty; i++) { TryMoveOrKill(ref softMoves, ref active, i, i, Category.Queen); } active = queen & (player ? black : white); for (int i = 1; i < 8 && !active.Empty; i++) { TryMoveOrKill(ref softMoves, ref active, -i, i, Category.Queen); } active = queen & (player ? black : white); for (int i = 1; i < 8 && !active.Empty; i++) { TryMoveOrKill(ref softMoves, ref active, -i, -i, Category.Queen); } active = queen & (player ? black : white); for (int i = 1; i < 8 && !active.Empty; i++) { TryMoveOrKill(ref softMoves, ref active, i, -i, Category.Queen); } active = queen & (player ? black : white); for (int i = 1; i < 8 && !active.Empty; i++) { TryMoveOrKill(ref softMoves, ref active, i, 0, Category.Queen); } active = queen & (player ? black : white); for (int i = 1; i < 8 && !active.Empty; i++) { TryMoveOrKill(ref softMoves, ref active, -i, 0, Category.Queen); } active = queen & (player ? black : white); for (int i = 1; i < 8 && !active.Empty; i++) { TryMoveOrKill(ref softMoves, ref active, 0, i, Category.Queen); } active = queen & (player ? black : white); for (int i = 1; i < 8 && !active.Empty; i++) { TryMoveOrKill(ref softMoves, ref active, 0, -i, Category.Queen); } //king TryMoveOrKill(ref softMoves, king & (player ? black : white), 1, -1, Category.King); TryMoveOrKill(ref softMoves, king & (player ? black : white), -1, 1, Category.King); TryMoveOrKill(ref softMoves, king & (player ? black : white), -1, -1, Category.King); TryMoveOrKill(ref softMoves, king & (player ? black : white), 1, 1, Category.King); TryMoveOrKill(ref softMoves, king & (player ? black : white), 1, 0, Category.King); TryMoveOrKill(ref softMoves, king & (player ? black : white), -1, 0, Category.King); TryMoveOrKill(ref softMoves, king & (player ? black : white), 0, 1, Category.King); TryMoveOrKill(ref softMoves, king & (player ? black : white), 0, -1, Category.King); //castle if (Player) { if (!(BlackARookMoved || BlackKingMoved)) { if (!(AllPieces.Get(new Position("b8")) || AllPieces.Get(new Position("c8")) || AllPieces.Get(new Position("d8")))) { softMoves.Add(new Move(Category.King, new Position("e8"), new Position("c8"), false)); } } if (!(BlackHRookMoved || BlackKingMoved)) { if (!(AllPieces.Get(new Position("f8")) || AllPieces.Get(new Position("g8")))) { softMoves.Add(new Move(Category.King, new Position("e8"), new Position("g8"), false)); } } } else { if (!(WhiteARookMoved || WhiteKingMoved)) { if (!(AllPieces.Get(new Position("b1")) || AllPieces.Get(new Position("c1")) || AllPieces.Get(new Position("d1")))) { softMoves.Add(new Move(Category.King, new Position("e1"), new Position("c1"), false)); } } if (!(WhiteHRookMoved || WhiteKingMoved)) { if (!(AllPieces.Get(new Position("f1")) || AllPieces.Get(new Position("g1")))) { softMoves.Add(new Move(Category.King, new Position("e1"), new Position("g1"), false)); } } } }
public CheckerPiece GetCheckerPiece(int row, int col) { return(AllPieces.Find(piece => piece.Status == CheckerPieceStatus.Alive && piece.Row == row && piece.Col == col)); }
void MakeNextPlacementPiece() { int numPieces = AllPieces.Count(); //have all the pieces been placed? if (Mathf.FloorToInt(numPieces / numPlayers) == PieceDatas.Count) { //start with player 0 currentPlayerIndex = players.Count - 1; Signals.Invoke(ESignalType.SetupComplete); NextPlayer(); return; } //for two players go 01100110 etc. currentPlayerIndex = Mathf.Clamp(Mathf.FloorToInt(numPieces / numPlayers) % 2 == 0 ? numPieces % numPlayers : (numPlayers - 1) - numPieces % numPlayers, 0, (numPlayers - 1)); int index = Mathf.FloorToInt(numPieces / 2); PieceData PieceData = PieceDatas[index]; Piece piece = ObjectFactory.Piece(PieceData); piece.name = PieceData.piecePrefab.name + " " + CurrentPlayer.Name; CurrentPlayer.pieces.Add(piece); if (piece.lockPivotHex) { piece.SetPivotHex(PieceData.lockedPivotHex, true); } piece.OnPieceClicked.AddListener(OnPieceClickedSetup); piece.OnMovementFinished.AddListener(OnMovementFinished); piece.OuterInactive = PieceColourPallet.OuterInactive(currentPlayerIndex); piece.OuterPivot = PieceColourPallet.OuterPivot(currentPlayerIndex); piece.OuterSelected = PieceColourPallet.OuterSelected(currentPlayerIndex); piece.InnerPivot = PieceColourPallet.InnerPivot(currentPlayerIndex); piece.InnerActive = PieceColourPallet.InnerActive(currentPlayerIndex); piece.InnerDisabled = PieceColourPallet.InnerDisabled(currentPlayerIndex); if (PieceData.useStartPosition) { PiecePlaced(piece); } else { SelectPiece(piece); currentBoard.HighlightPlayer(currentPlayerIndex); Signals.Invoke(ESignalType.PlayerTurn, currentPlayerIndex); } if (currentSelectedPiece) { SetPieceModeSetup(currentSelectedPiece); } }