コード例 #1
0
    void OnMoveCompleted(PlayersMove move)
    {
        if (this.ValidateMove(move))
        {
            // Update game board
            this.currentPlayer.OnMoveCompleted -= this.dOnMoveCompleted;
            this.gameBoard.SetTileState(move.Row, move.Col, this.currentPlayer.Type);

            // Check if game is over
            TileMark?winningType;
            if (this.gameBoard.CheckGameOverCondition(out winningType))
            {
                // Winner could be only the player, who was making last turn
                this.previousGameInfo.WinnerIdx = winningType == null ? -1 : this.currentPlayerIdx;

                if (this.OnGameOver != null)
                {
                    this.OnGameOver(winningType == null ? null : this.players[this.currentPlayerIdx]);
                }
                return;
            }

            // If not game over - start next turn
            this.StartNextTurn(move);
        }
    }
コード例 #2
0
 protected void FireOnMoveCompleted(PlayersMove move)
 {
     if (this.OnMoveCompleted != null)
     {
         this.OnMoveCompleted(move);
     }
 }
コード例 #3
0
    public bool TryApplyMove(ref MinMaxNode <int> node, PlayersMove move)
    {
        MinMaxNode <int> nextNode = node.Children.FirstOrDefault(n => n.Data == move.Hash);

        if (nextNode != null)
        {
            node = nextNode;
            return(true);
        }

        return(false);
    }
コード例 #4
0
    int AddChildren(MinMaxNode <int> node, BoardState state, int depth)
    {
        MinMaxNode <int>[] children = new MinMaxNode <int> [9 - depth];
        int playerType = depth % 2;
        int childIdx   = -1;

        for (int i = 0; i < 9; ++i)
        {
            if (state[i] == 0)
            {
                PlayersMove      move  = new PlayersMove(i / 3, i % 3);
                MinMaxNode <int> child = new MinMaxNode <int>(move.Hash, 0);

                state.SetTile(i, playerType + 1);
                int winner = state.GetWinner();

                if (winner != -1)
                {
                    child.Score = winner == 1 ? int.MaxValue : (winner == 2 ? int.MinValue : 0);
                }
                else
                {
                    child.Score = this.AddChildren(child, state, depth + 1);
                }

                // Restore board state as it was before this move
                state.SetTile(i, 0);

                // Add child to current node
                children[++childIdx] = child;
                ++this.nodesCountByDepth[depth];
            }
        }

        System.Array.Sort <MinMaxNode <int> >(children);
        node.Children = children;
        return((playerType == 0 ? node.MaxChild : node.MinChild).Score);
    }
コード例 #5
0
 bool ValidateMove(PlayersMove move)
 {
     return(this.gameBoard[move.Row, move.Col] == TileMark.Empty);
 }