Exemple #1
0
    public void CheckMatches(int playerNum)
    {
        Piece[][][] b = BoardStateUtils.GenerateBoardState(_moves);

        Match[] matches = BoardChecker.FindMatches(b);
        Messenger <Match[]> .Broadcast(GameEvent.PIECES_MATCHED, matches);

        Match[] currentPlayerMatches = matches.Where(match => match.playerNum == playerNum).ToArray();
        if (currentPlayerMatches.Length == 3)
        {
            Debug.Log("All Pieces Matched!");
            gameOver = true;
            Messenger <int> .Broadcast(GameEvent.GAME_OVER, playerNum);
        }
    }
Exemple #2
0
    public static int minimax(int depth, List <Move> movesPlayed, int alpha, int beta, bool isMaximisingPlayer)
    {
        if (depth == 0 || IsTerminalState(BoardStateUtils.GenerateBoardState(movesPlayed)))
        {
            return(-GetBoardValue(BoardStateUtils.GenerateBoardState(movesPlayed)));
        }
        List <Move> shuffledMoves = BoardStateUtils.EnumerateAvailableMoves(movesPlayed);

        if (isMaximisingPlayer)
        {
            int bestMove = -9999;
            foreach (Move move in shuffledMoves)
            {
                List <Move> newMoves = new List <Move>(movesPlayed);
                newMoves.Add(move);
                bestMove = Math.Max(bestMove, minimax(depth - 1, newMoves, alpha, beta, !isMaximisingPlayer));
                alpha    = Math.Max(alpha, bestMove);
                if (beta <= alpha)
                {
                    return(bestMove);
                }
            }
            return(bestMove);
        }
        else
        {
            int bestMove = 9999;
            foreach (Move move in shuffledMoves)
            {
                List <Move> newMoves = new List <Move>(movesPlayed);
                newMoves.Add(move);
                bestMove = Math.Min(bestMove, minimax(depth - 1, newMoves, alpha, beta, !isMaximisingPlayer));
                beta     = Math.Min(beta, bestMove);
                if (beta <= alpha)
                {
                    return(bestMove);
                }
            }
            return(bestMove);
        }
    }