Ejemplo n.º 1
0
    private void generateAndPlaceTiles()
    {
        int rows    = GameBoardInformation.rows;
        int columns = GameBoardInformation.columns;

        boardUITiles = new GameObject[rows, columns];

        int     maximum        = rows > columns ? rows : columns;
        Vector3 cameraPosition = new Vector3(rows / 2.0f, -columns / 2.0f, -10.0f);

        _camera.orthographicSize   = estimatedTileCameraSize * maximum;
        _camera.transform.position = cameraPosition;

        for (int i = 0; i < rows; ++i)
        {
            for (int j = 0; j < columns; ++j)
            {
                GameObject newTile;
                Vector3    tilePosition = new Vector3(j, -i, 0.0f);
                if (GameBoardInformation.getPieceIntensity(i, j) == MaterialIntensity.DARK)
                {
                    newTile = Instantiate(DarkTilePrefab, tilePosition, Quaternion.identity, transform);
                }
                else
                {
                    newTile = Instantiate(LightTilePrefab, tilePosition, Quaternion.identity, transform);
                }
                newTile.transform.Rotate(new Vector3(0.0f, 180.0f, 0.0f));
                newTile.AddComponent <BoxCollider>();
                newTile.name       = "Index (" + i + ", " + j + ")";
                boardUITiles[i, j] = newTile;
            }
        }
    }
Ejemplo n.º 2
0
    // This function should be called when we want this player to play
    public IEnumerator PlayTurn()
    {
        yield return(new WaitUntil(() => playerTurnIndex == globalTurn)); // only play when it is the current player's turn

        if (GameBoardInformation.isGameOver == true)
        {
            WriteTextFile.Write();
            yield break;
        }
        else
        {
            StartCoroutine(MakeMove()); // This is where the player will actually perform the move.
            yield return(new WaitUntil(() => finishedMove == true));

            finishedMove = false; // resets to false, to allow the player to play again
            GameTree.UpdateGameStateAndTree(lastMove);
            TechnicalStatistics.LastHeuristic    = GameTree.head.HeuristicValue;
            TechnicalStatistics.LastMoveString   = TechnicalStatistics.GetLastMoveString(GameTree.head, secondsPassed);
            TechnicalStatistics.totalTimePassed += secondsPassed;

            // once we reach here, all the parameters of TechnicalStatistics have been updated properly.
            // Therefore, we will add this move to our List of moves here.
            WriteTextFile.AddMove();

            GameBoardInformation.updateGameOver();
            globalTurn = (globalTurn + 1) % 2; // increase index to say that it is the other player's turn
            yield return(PlayTurn());
        }
    }
Ejemplo n.º 3
0
    private void UpdateTileMaterial(int i, int j, Piece piece)
    {
        MaterialIntensity intensity = GameBoardInformation.getPieceIntensity(i, j);

        Material updatedMaterial = null;

        if (intensity == MaterialIntensity.DARK)
        {
            switch (piece)
            {
            case Piece.BLACKQUEEN:
                updatedMaterial = DarkTileBlackQueen;
                break;

            case Piece.DESTROYEDTILE:
                updatedMaterial = DarkTileFire;
                break;

            case Piece.EMPTY:
                updatedMaterial = DarkCubeMaterialEmpty;
                break;

            case Piece.WHITEQUEEN:
                updatedMaterial = DarkTileWhiteQueen;
                break;
            }
        }
        else
        {
            switch (piece)
            {
            case Piece.BLACKQUEEN:
                updatedMaterial = LightTileBlackQueen;
                break;

            case Piece.DESTROYEDTILE:
                updatedMaterial = LightTileFire;
                break;

            case Piece.EMPTY:
                updatedMaterial = LightCubeMaterialEmpty;
                break;

            case Piece.WHITEQUEEN:
                updatedMaterial = LightTileWhiteQueen;
                break;
            }
        }

        boardUITiles[i, j].GetComponent <Renderer>().material = updatedMaterial;
        if (updatedMaterial == null)
        {
            Debug.LogError("GameLogic.cs, updateTileMaterial: updatedMaterial is null.");
        }
    }
Ejemplo n.º 4
0
    IEnumerator Play()
    {
        StartCoroutine(player1.PlayTurn());
        StartCoroutine(player2.PlayTurn());
        yield return(new WaitUntil(() => GameBoardInformation.GetWinner() != Piece.EMPTY));

        Debug.Log("Winner is = " + GameBoardInformation.GetWinner().ToString());
        //WriteTextFile.Write();
        yield return(new WaitUntil(() => GameBoardInformation.playAgain == true));

        resetGame(); // TODO: Complete implementation
        yield return(Play());
    }
Ejemplo n.º 5
0
    // Start is executed once
    void Start()
    {
        int rows    = InitializingParameters.rows;
        int columns = InitializingParameters.columns;

        List <Indices> WhiteQueens = InitializingParameters.WhiteQueens;
        List <Indices> BlackQueens = InitializingParameters.BlackQueens;

        GameBoardInformation.InitializeBoard(rows, columns, WhiteQueens, BlackQueens);
        generateAndPlaceTiles();

        // initialize players as Humans/AIs as requested
        InitializePlayersAsHumansOrAIs();

        // Players identities are finally recognized, we can start playing!
        StartCoroutine(Play());
    }
    // this function should be called only at the end of the game, where it will write
    // all the moves to the files
    public static void Write()
    {
        Piece winner = GameBoardInformation.GetWinner();

        if (winner != Piece.EMPTY)
        {
            MoveList.Add("Winner: " + winner);
        }
        else
        {
            MoveList.Add("Time's up! AI Lost.");
        }
        List <string> text = new List <string>();

        text.Add(GameBoardInformation.rows + "x" + GameBoardInformation.columns + "\n");
        foreach (string str in MoveList)
        {
            text.Add(str);
        }
        string[] lines = text.ToArray();
        System.IO.File.WriteAllLines(@".\GameMoves.txt", lines);
    }
    // Update is called once per frame
    void Update()
    {
        TimeLeft.text          = "Time Left: " + string.Format("{0:0.00}", (InitializingParameters.time - TechnicalStatistics.totalTimePassed)) + "sec";
        LastMove.text          = "Move: " + TechnicalStatistics.LastMoveString;
        TreeDepth.text         = "Total Tree Depth: " + TechnicalStatistics.TotalDepth;
        LocalDepth.text        = "Local Tree Depth: " + TechnicalStatistics.LocalDepth;
        AlphaBetaPruning.text  = "Alpha Beta Pruning: " + TechnicalStatistics.AlphaBetaPruning;
        SiblingPruning.text    = "Sibling Pruning Percentage: " + string.Format("{0:0.00}", 100.0 * (((double)TechnicalStatistics.PrunedSiblings) / TechnicalStatistics.TotalWouldBeNodes)) + "%";
        DepthPruning.text      = "Depth Pruning Percentage: " + string.Format("{0:0.00}", 100.0 * (((double)TechnicalStatistics.PrunedDepth) / TechnicalStatistics.TotalWouldBeNodes)) + "%";
        Threads.text           = "All Threads Opened (In Last Move): " + TechnicalStatistics.ThreadAmount;
        ConcurrentThreads.text = "Concurrent Threads Opened (In Last Move): " + TechnicalStatistics.MaxConcurrentThreads;
        TotalNodesCreated.text = "Nodes Created: " + TechnicalStatistics.TotalCreatedNodes;
        TotalNodesIgnored.text = "Nodes Created+Ignored: " + TechnicalStatistics.TotalWouldBeNodes;
        HeuristicValue.text    = "The Variant Estimate: " + string.Format("{0:0.00}", TechnicalStatistics.LastHeuristic);
        UltimateValue.text     = "The Principal Variation: " + string.Format("{0:0.00}", TechnicalStatistics.UltimateHeuristic);
        Piece Winner = GameBoardInformation.GetWinner();

        WinnerValue.text = "Winner: " + Winner;
        if (Winner != Piece.EMPTY)
        {
            WinnerValue.transform.localScale = new Vector3(1, 1, 1);
        }
    }
Ejemplo n.º 8
0
 protected bool BurnPiece(int source_i, int source_j, int destination_i, int destination_j)
 {
     return(GameBoardInformation.burnPiece(source_i, source_j, destination_i, destination_j));
 }
Ejemplo n.º 9
0
 protected bool MovePiece(int i, int j, int destination_i, int destination_j)
 {
     return(GameBoardInformation.movePiece(i, j, destination_i, destination_j));
 }
Ejemplo n.º 10
0
 private void resetGame()
 {
     GameBoardInformation.playAgain = false;
     PlayerLogic.reset();
     GameBoardInformation.reset(); // TODO: Do not forget to implement reset!
 }
Ejemplo n.º 11
0
    // Note: This function is NOT recursive.
    protected sealed override IEnumerator MakeMove()
    {
        // wait until select the queen
        Debug.Log("Player " + playerTurnIndex + ", Please Select Queen");
        yield return(new WaitUntil(() => selectedIndices != null));

        int queen_i = selectedIndices.i;
        int queen_j = selectedIndices.j;

        selectedIndices = null;

        // check if player selected a correct queen.
        if ((int)GameBoardInformation.getPieceAt(queen_i, queen_j) != playerTurnIndex)
        {
            Debug.Log("Player " + playerTurnIndex + ", Inappropriate QUEEN Tile");
            yield return(MakeMove());

            yield break;
        }

        // wait until select move location
        Debug.Log("Player " + playerTurnIndex + ", Please Select Move Location");
        yield return(new WaitUntil(() => selectedIndices != null));

        int destination_i = selectedIndices.i;
        int destination_j = selectedIndices.j;

        selectedIndices = null;

        // move the queen
        bool didMove = MovePiece(queen_i, queen_j, destination_i, destination_j);

        if (didMove == false)
        {
            Debug.Log("Player " + playerTurnIndex + ", Inappropriate MOVE Tile");
            yield return(MakeMove());

            yield break;
        }

        // wait until select burn location
        Debug.Log("Player " + playerTurnIndex + ", Please Select BURN Location");
        yield return(new WaitUntil(() => selectedIndices != null));

        int burn_i = selectedIndices.i;
        int burn_j = selectedIndices.j;

        selectedIndices = null;

        bool didBurn = BurnPiece(destination_i, destination_j, burn_i, burn_j);

        if (didBurn == false)
        {
            Debug.Log("Player " + playerTurnIndex + ", Inappropriate BURN Tile");
            MovePiece(destination_i, destination_j, queen_i, queen_j); // reset the damage done
            yield return(MakeMove());

            yield break;
        }

        lastMove     = new PlayerMove((playerTurnIndex == 0) ? Piece.WHITEQUEEN : Piece.BLACKQUEEN, queen_i, queen_j, destination_i, destination_j, burn_i, burn_j);
        finishedMove = true;
    }