Esempio n. 1
0
        private void SimulateMouseEvents(Move move)
        {
            var startSquare = this.Controls["sq" + move.StartSquare];

            startSquare.BackColor = Color.Gray;
            sq_MouseClick(startSquare, null);
            startSquare.BackColor = Color.Green;

            var endSquare = this.Controls["sq" + move.EndSquare];

            endSquare.BackColor = Color.Gray;
            sq_MouseClick(endSquare, null);
            endSquare.BackColor = Color.Green;
        }
Esempio n. 2
0
        private List<Move> GetMoves(Player.PlayerColor playerColor)
        {
            PrepareBitBoards();

            var moves = new List<Move>();

            for (Byte index = 0; index < _board.Length; index++)
            {
                Player.PlayerColor currentSquareCheckerColor = Player.GetCheckerColor((Piece)_board[index]);
                if (currentSquareCheckerColor == playerColor)
                {
                    switch ((Piece)_board[index])
                    {
                        case Piece.WhiteKing:
                        case Piece.RedKing:
                            if (CanMoveNW(index))
                            {
                                Byte endSquare = GetSquareFromBitboard(whiteAttackSquares[index][0]);
                                var move = new Move(index, endSquare, false) { WillKing = IsKingingSquare(endSquare) };
                                moves.Add(move);
                            }

                            if (CanMoveNE(index))
                            {
                                Byte endSquare = GetSquareFromBitboard(whiteAttackSquares[index][1]);
                                var move = new Move(index, endSquare, false) { WillKing = IsKingingSquare(endSquare) };
                                moves.Add(move);
                            }

                            if (CanMoveSW(index))
                            {
                                Byte endSquare = GetSquareFromBitboard(redAttackSquares[index][0]);
                                var move = new Move(index, endSquare, false) { WillKing = IsKingingSquare(endSquare) };
                                moves.Add(move);
                            }

                            if (CanMoveSE(index))
                            {
                                Byte endSquare = GetSquareFromBitboard(redAttackSquares[index][1]);
                                var move = new Move(index, endSquare, false) { WillKing = IsKingingSquare(endSquare) };
                                moves.Add(move);
                            }

                            break;

                        case Piece.WhiteChecker:
                            if (CanMoveNW(index))
                            {
                                Byte endSquare = GetSquareFromBitboard(whiteAttackSquares[index][0]);
                                var move = new Move(index, endSquare, false) { WillKing = IsKingingSquare(endSquare) };
                                moves.Add(move);
                            }

                            if (CanMoveNE(index))
                            {
                                Byte endSquare = GetSquareFromBitboard(whiteAttackSquares[index][1]);
                                var move = new Move(index, endSquare, false) { WillKing = IsKingingSquare(endSquare) };
                                moves.Add(move);
                            }

                            break;

                        case Piece.RedChecker:
                            if (CanMoveSW(index))
                            {
                                Byte endSquare = GetSquareFromBitboard(redAttackSquares[index][0]);
                                var move = new Move(index, endSquare, false) { WillKing = IsKingingSquare(endSquare) };
                                moves.Add(move);
                            }

                            if (CanMoveSE(index))
                            {
                                Byte endSquare = GetSquareFromBitboard(redAttackSquares[index][1]);
                                var move = new Move(index, endSquare, false) { WillKing = IsKingingSquare(endSquare) };
                                moves.Add(move);
                            }

                            break;
                    }
                }
            }

            return moves;
        }
Esempio n. 3
0
        private void MakeMove(Move move)
        {
            _boardStack.Push((Byte[])_board.Clone());

            _board[move.EndSquare] = _board[move.StartSquare];
            _board[move.StartSquare] = 0;

            // King the checker
            if (_board[move.EndSquare] < 3 && IsKingingSquare(move.EndSquare))
            {
                _board[move.EndSquare] += 2;
                move.WillKing = true;
            }

            if (move.IsJump)
            {
                Byte js = GetJumpedSquare(move.StartSquare, move.EndSquare);
                _board[js] = 0;
            }

            PrepareBitBoards();
        }
Esempio n. 4
0
 private void FindJumpsFromSquare(Byte startSquare, Move move)
 {
     //NW
     if (CanJumpNW((Piece)_board[startSquare], startSquare))
     {
         Move m = CreateMoveFromJump(startSquare, MoveDirection.NW);
         move.Jumps.Add(m);
         MakeMove(m);
         FindJumpsFromSquare(m.EndSquare, m);
         UndoMove();
     }
     //NE
     if (CanJumpNE((Piece)_board[startSquare], startSquare))
     {
         Move m = CreateMoveFromJump(startSquare, MoveDirection.NE);
         move.Jumps.Add(m);
         MakeMove(m);
         FindJumpsFromSquare(m.EndSquare, m);
         UndoMove();
     }
     //SW
     if (CanJumpSW((Piece)_board[startSquare], startSquare))
     {
         Move m = CreateMoveFromJump(startSquare, MoveDirection.SW);
         move.Jumps.Add(m);
         MakeMove(m);
         FindJumpsFromSquare(m.EndSquare, m);
         UndoMove();
     }
     //SE
     if (CanJumpSE((Piece)_board[startSquare], startSquare))
     {
         Move m = CreateMoveFromJump(startSquare, MoveDirection.SE);
         move.Jumps.Add(m);
         MakeMove(m);
         FindJumpsFromSquare(m.EndSquare, m);
         UndoMove();
     }
 }
Esempio n. 5
0
        private Move CreateMoveFromJump(Byte index, MoveDirection direction)
        {
            String key = index.ToString() + direction.ToString().ToLower();
            Byte landingSquare = JumpLandingSquareLookup[key];
            Move move = new Move(index, landingSquare, true);

            return move;
        }
Esempio n. 6
0
 private void RemoveJumpedPiece(Move move)
 {
     Byte js = _engine.GetJumpedSquare(move.StartSquare, move.EndSquare);
     _board[js] = 0;
 }
Esempio n. 7
0
        private void MakeMove(Move move)
        {
            _board[move.EndSquare] = _board[move.StartSquare];
            _board[move.StartSquare] = 0;

            // King the checker
            if ((_kingSquares.Contains(move.EndSquare)) && (_board[move.EndSquare] < 3))
                _board[move.EndSquare] += 2;

            if (move.IsJump)
            {
                RemoveJumpedPiece(move);
                foreach (Move m in move.Jumps)
                    MakeMove(m);
            }
        }
Esempio n. 8
0
 private Boolean DoMustJumpLogic(Move move)
 {
     if (move.HasChildMoves && move.WillKing == false)
     {
         mustJumpFromSquare = move.EndSquare;
         jumpChoices = move.Jumps;
         return true;
     }
     else
     {
         mustJumpFromSquare = 0;
         jumpChoices.Clear();
         return false;
     }
 }