Esempio n. 1
0
    public void SaveBoard(bool playersTurn, string name)
    {
        //open stream with
        SaveLoadStream = new StreamWriter(Application.dataPath + "/Resources/" + name + ".txt");

        //save board from dll
        string row = "";

        for (int y = 0; y < 8; y++)
        {
            for (int x = 0; x < 8; x++)
            {
                row += (char)DLLFunctions.GetPiece(x, y);
            }

            if (y != 7)
            {
                row += Environment.NewLine;
            }
        }

        //send to file
        instance.Save(row);
        instance.Save(playersTurn.ToString());

        SaveLoadStream.Close();
    }
Esempio n. 2
0
 public void Start()
 {
     //if on options page
     if (SceneManager.GetActiveScene().name == "Options")
     {
         //assign depth value to slider for player feedback
         GameObject.Find("DifficultySlider").GetComponent <Slider>().value = DLLFunctions.GetDepth();
     }
 }
Esempio n. 3
0
    // Use this for initialization
    public void Start()
    {
        Utils.isPaused = Utils.isGameOver = once
                                                = playerVs = playerVsAI = AiVsAi = false;

        //sets the game type
        switch (Utils.type)
        {
        case (int)Utils.GameMode.PvP:
            playerVs = true;
            DLLFunctions.ResetBoard();
            break;

        case (int)Utils.GameMode.PvE:
            playerVsAI = true;
            DLLFunctions.ResetBoard();
            break;

        case (int)Utils.GameMode.EvE:
            AiVsAi = true;
            DLLFunctions.ResetBoard();
            break;

        default:
            playerVsAI = true;
            DLLFunctions.ResetBoard();
            break;
        }

        //generate new board
        GenerateBoard();

        forcedPieces = new List <Piece>();
        validMove    = new List <Piece>();

        GameReady = true;

        //output new game start/dark team up first
        DebugLog.Instance.Write("A new game has began" + System.Environment.NewLine + "It's dark team up first" + System.Environment.NewLine);

        //announce whos playing dark
        if (playerVs)
        {
            DebugLog.Instance.Write("Human player 1");
        }
        else if (playerVsAI)
        {
            DebugLog.Instance.Write("Human player");
        }
        else if (AiVsAi)
        {
            DebugLog.Instance.Write("A.I. Player 1");
        }
    }
Esempio n. 4
0
        internal static bool GetEntityAPI(out DLLFunctions pFunctionTable)
        {
            Log.Message("Request DLLFunctions interface");

            if (InterfaceUtils.SetupInterface(ServerManagedAPI.DelegateInstanceNamePrefix, out pFunctionTable, Wrapper.DLLFunctions))
            {
                Wrapper.DLLFunctionsInterface = pFunctionTable;
                return(true);
            }

            return(false);
        }
Esempio n. 5
0
    //generate grid and assign pieces
    private void GenerateBoard()
    {
        //generate board from dll checkersboard
        for (int y = 0; y < 8; y++)
        {
            for (int x = 0; x < 8; x++)
            {
                GeneratePiece((char)DLLFunctions.GetPiece(x, y), x, y);
            }
        }

        //output initial board
        DebugLog.Instance.Write("The board has been generated as");
        DebugLog.Instance.OutPutBoard(isDark);
    }
Esempio n. 6
0
    //output board for log
    public void OutPutBoard(bool playersTurn)
    {
        //output board from dll
        string row = "";

        for (int y = 0; y < 8; y++)
        {
            for (int x = 0; x < 8; x++)
            {
                row += (char)DLLFunctions.GetPiece(x, y);
            }
            row += Environment.NewLine;
        }

        EchoToConsole = AddTimeStamp = false; //turn off flags
        Write(row);                           //output board to write
        EchoToConsole = AddTimeStamp = true;  //turn on flags
    }
Esempio n. 7
0
    private void UpdateBoard()
    {
        for (int y = 0; y < 8; y++)
        {
            for (int x = 0; x < 8; x++)
            {
                //erase current board
                Piece p = pieces[x, y];
                if (p != null)
                {
                    pieces[x, y] = null;
                    Destroy(p.gameObject);
                }

                //reinitialises the board with updated values
                GeneratePiece((char)DLLFunctions.GetPiece(x, y), x, y);
            }
        }
    }
Esempio n. 8
0
    //attempt move
    private void TryMove(float xX, float xY)
    {
        int startX = -1; int startY = -1;
        int endX = -1; int endY = -1;

        //if out of bounds == -1
        if (xX == -1 || xY == -1)
        {
            //if piece is selected
            if (selectedPiece != null)
            {
                startX = Utils.PosToArrayIndex(startDrag.x);
                startY = Utils.PosToArrayIndex(startDrag.y);

                //move piece back to start position
                PlacePiece(selectedPiece, startX, startY);
            }

            //let go of piece
            startDrag     = Vector2.zero;
            selectedPiece = null;
            return;
        }
        else
        {
            //convert world position into grid index
            startX = Utils.PosToArrayIndex(startDrag.x);
            startY = Utils.PosToArrayIndex(startDrag.y);

            //convert world position into grid index
            endDrag = new Vector2(xX, xY);
            endX    = Utils.PosToArrayIndex(endDrag.x);
            endY    = Utils.PosToArrayIndex(endDrag.y);
        }

        //if piece is selected
        if (selectedPiece != null)
        {
            //if it hasnt moved
            if (endDrag == startDrag)
            {
                //move piece back to start position
                PlacePiece(selectedPiece, startX, startY);

                //drop piece
                startDrag     = Vector2.zero;
                selectedPiece = null;
                return;
            }

            //if the move is valid
            if (selectedPiece.validMove(pieces, startDrag, endDrag))
            {
                //did we kill something
                if (Mathf.Abs(Utils.PosToArrayIndex(endDrag.y) - Utils.PosToArrayIndex(startDrag.y)) == 2)
                {
                    //turn potentially captured pieces world position into grid index
                    int x = Utils.PosToArrayIndex((startDrag.x + endDrag.x) / 2);
                    int y = Utils.PosToArrayIndex((startDrag.y + endDrag.y) / 2);

                    Piece p = pieces[x, y];

                    //if a piece is at this grid coordinate
                    if (p != null)
                    {
                        //destroy piece, remove from grid, and flag kill
                        Destroy(p.gameObject);
                        pieces[x, y] = null;
                        hasKilled    = true;
                    }
                }

                //were we supposed to kill anything
                if (forcedPieces.Count != 0 && !hasKilled)
                {
                    //move piece back to start position
                    PlacePiece(selectedPiece, startX, startY);

                    //drop piece
                    startDrag     = Vector2.zero;
                    selectedPiece = null;
                    return;
                }

                Piece temp = pieces[endX, endY];

                //move selected piece in array
                pieces[endX, endY] = selectedPiece;

                //remove selected place from previous spot in array
                pieces[startX, startY] = temp;

                //update the pieces location
                PlacePiece(selectedPiece, endX, endY);

                //output old board
                DebugLog.Instance.Write("The board before");
                DebugLog.Instance.OutPutBoard(isDark);

                //update board with player's move
                if (hasKilled)
                {
                    DLLFunctions.UpdateBoardWithCapture(endX, endY, startX, startY);
                }
                else
                {
                    DLLFunctions.UpdateBoardWithMove(endX, endY, startX, startY);
                    DebugLog.Instance.Write(selectedPiece.name + " has moved from " + Utils.IndexToStr(startX, startY) + " to " + Utils.IndexToStr(endX, endY));
                }

                //output new board
                DebugLog.Instance.Write("The board after");
                DebugLog.Instance.OutPutBoard(isDark);

                EndTurn();
                CheckForVictory();
            }
            else
            {
                //if piece selected
                if (selectedPiece != null)
                {
                    //move back to starting position
                    PlacePiece(selectedPiece, startX, startY);
                }

                //drop piece
                startDrag     = Vector2.zero;
                selectedPiece = null;
                forcedPieces.Clear();
                validMove.Clear();
            }
        }
    }
Esempio n. 9
0
    private void DoAIMove()
    {
        //output old board
        DebugLog.Instance.Write("The board before search");
        DebugLog.Instance.OutPutBoard(isDark);

        //perform turn
        DLLFunctions.SearchMove(isDark);

        //small delay to allow the AI's move to be shown
        float delay = 2.0f;

        while (delay > 0)
        {
            delay -= Time.deltaTime;
        }
        UpdateBoard();

        //output new board
        DebugLog.Instance.Write("The board after search");
        DebugLog.Instance.OutPutBoard(isDark);

        //end turn
        numTurns++;
        isDark = !isDark;

        //output whos turn and/or team it is
        if (AiVsAi)
        {
            if (isDark)
            {
                DebugLog.Instance.Write("It's Dark team's turn");
                DebugLog.Instance.Write("A.I. Player 1");
            }
            else
            {
                DebugLog.Instance.Write("It's Light team's turn");
                DebugLog.Instance.Write("A.I. Player 2");
            }
        }

        if (playerVsAI)
        {
            if (isDark)
            {
                DebugLog.Instance.Write("It's Dark team's turn");
            }
        }

        //test to see if there are any forced capture moves
        forcedPieces = scanForPossMove();

        //checks for number of valid moves
        validMove = scanForValidMove();

        //output valid/forced moves for current player
        DebugLog.Instance.Write("has " + forcedPieces.Count + " forced moves");
        DebugLog.Instance.Write("has " + validMove.Count + " valid moves");

        //if there are forced capture pieces
        if (forcedPieces.Count != 0)
        {
            //then valid move's is forced move's
            validMove = forcedPieces;
        }

        //check victory
        CheckForVictory();
    }
Esempio n. 10
0
    public void UpdateBoardFromBoard(char[,] loaded)
    {
        //clear current board
        DLLFunctions.Clear();

        for (int y = 0; y < 8; y++)
        {
            for (int x = 0; x < 8; x++)
            {
                //wipe out piece
                Piece p = pieces[x, y];
                if (p != null)
                {
                    pieces[x, y] = null;
                    Destroy(p.gameObject);
                }

                //generate new piece from the board
                GeneratePiece(loaded[x, y], x, y);


                p = pieces[x, y];

                //tell the board about the new position of the kings and regular pieces
                if (p != null)
                {
                    if (p.isDark)
                    {
                        if (p.isKing)
                        {
                            DLLFunctions.SetP1King(Utils.Index(x, y));
                        }
                        else
                        {
                            DLLFunctions.SetP1Man(Utils.Index(x, y));
                        }
                    }

                    if (p.isLight)
                    {
                        if (p.isKing)
                        {
                            DLLFunctions.SetP2King(Utils.Index(x, y));
                        }
                        else
                        {
                            DLLFunctions.SetP2Man(Utils.Index(x, y));
                        }
                    }
                }
            }

            //test to see if there are any forced capture moves
            forcedPieces = scanForPossMove();

            //checks for number of valid moves
            validMove = scanForValidMove();

            //if there are forced capture pieces
            if (forcedPieces.Count != 0)
            {
                //then valid move's is forced move's
                validMove = forcedPieces;
            }
        }
    }
Esempio n. 11
0
 public void SetDepthVal(float val)
 {
     DLLFunctions.ChangeDepth((int)val);
 }