private void ValidateButton_Click(object sender, RoutedEventArgs e)
 {
     //UpdateBoard();
     if (MoveValidator.Validate(game.gs, BoardCharView, game.movementRecorder) != -1 && !game.GameEnd())
     {
         ListingWords(game.gs.CorrectWords);
         game.UpdateState(BoardCharView);
         GetNewTiles();
         LogBoardWriter(game.gs.ListOfPlayers[PlayerNow].ToString());
         PlayerNow = game.NextPlayer();
         UpdatePlayerInfoLbl(PlayerNow);
         Console.WriteLine("PlayerNow:" + PlayerNow);
         //gs.Update(bc, PlayerNow, sum);
         LoadBoardView();
         LoadRackView();
     }
     else
     {
         LogBoardWriter("Game Judge: \"You didn't score. Please try again!\"");
         LoadBoardView();
         Retry();
     }
     if (game.GameEnd())
     {
         foreach (Player p in game.gs.ListOfPlayers)
         {
             LogBoardWriter(game.gs.ListOfPlayers[PlayerNow].ToString());
         }
         game.gs.ListOfPlayers.Sort();
         LogBoardWriter("Game Winner is Player " + (game.gs.ListOfPlayers[0].Id + 1) + " with scores" + (game.gs.ListOfPlayers[0].Score) + "!!!");
     }
 }
Beispiel #2
0
 public bool Validate(char[,] bc)
 {
     if (MoveValidator.Validate(gs, bc, moveRecorder) != -1 && !GameEnd())
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #3
0
        public IEnumerable <IMove> GetLegalMoves(ushort squareIndex, ulong[][] occupancy, ushort?enPassantIdx,
                                                 CastlingAvailability castlingAvailability)
        {
            var pieceOfColor = occupancy.GetPieceOfColorAtIndex(squareIndex);

            if (pieceOfColor == null)
            {
                yield break;
            }

            var piece = pieceOfColor.Value.Piece;
            var color = pieceOfColor.Value.Color;

            var relevantOccupancy = occupancy.Occupancy();

            if (piece == Piece.Pawn && enPassantIdx.HasValue)
            {
                var epValue = enPassantIdx.Value.GetBoardValueOfIndex();
                relevantOccupancy |= epValue;
            }

            var pseudoLegalMoves = GetPseudoLegalMoves(squareIndex, piece, color, relevantOccupancy);
            var moves            = new List <IMove>();

            foreach (var destinationIndex in pseudoLegalMoves.GetSetBits())
            {
                var moveType = BoardHelpers.GetMoveType(occupancy, squareIndex, destinationIndex, enPassantIdx);
                var move     = MoveHelpers.GenerateMove(squareIndex, destinationIndex, moveType);
                moves.Add(move);
            }

            if (piece == Piece.King && IsKingSquare(squareIndex, color))
            {
                moves.AddRange(GetPseudoLegalCastlingMoves(color, castlingAvailability));
            }

            foreach (var move in moves)
            {
                var moveValidator =
                    new MoveValidator(
                        new Board(occupancy, 0, enPassantIdx, null, castlingAvailability, color, 0, true),
                        move);
                var validationResult = moveValidator.Validate();
                if (validationResult == MoveError.NoneSet)
                {
                    yield return(move);
                }
            }
        }
Beispiel #4
0
    public void DoMove(MoveData move)
    {
        m_moveValidator.Validate(move);

        if (move.m_startCoordinate.m_isOnGrid)
        {
            var startGridCoordinate = move.m_startCoordinate.m_gridCoordinate;
            SetCellColor(startGridCoordinate, BoardCellColor.Empty);
        }

        var color             = move.GetMoveColor();
        var endGridCoordinate = move.m_endCoordinate.m_gridCoordinate;

        SetCellColor(endGridCoordinate, color);
    }
Beispiel #5
0
        public User.User MakeMove(Move.Move move)
        {
            MoveValidator.Validate(BuildInput(move));

            SetPlayerOnBoard(move);

            DoRowSum(move);

            DoColoumnSum(move);

            SetDiagnolMove(move);

            SetReverseDiagnolMove(move);

            //SetWinner(move);

            return(Winner);
        }