Ejemplo n.º 1
0
        public static void DisplayBoard(GameBoardData i_GameData)
        {
            StringBuilder gameBoardString = new StringBuilder();

            Screen.Clear();
            gameBoardString.AppendFormat("{1}{0}", Environment.NewLine, k_MainHeader);
            gameBoardString.AppendFormat("{1}{0}{2}{0}", Environment.NewLine, k_TableHeader, k_Separator);
            gameBoardString.AppendFormat("| {1} |{2}|{0}{3}{0}", Environment.NewLine, k_HiddenGuess, k_EmptyResult, k_Separator);

            for (int i = 0; i < i_GameData.TotalNumberOfTurns; i++)
            {
                if (i >= i_GameData.TurnsPlayed)
                {
                    gameBoardString.AppendFormat("| {1} |{2}|{0}{3}{0}", Environment.NewLine, k_EmptyGuess, k_EmptyResult, k_Separator);
                }
                else
                {
                    gameBoardString.AppendFormat(
                        "| {1} |{2}|{0}{3}{0}",
                        Environment.NewLine,
                        IOConvertors.PinArrayToStringConvertor(i_GameData.GetTurn(i).Guess),
                        IOConvertors.resultStringBuilder(i_GameData.GetTurn(i).Results),
                        k_Separator);
                }
            }

            System.Console.WriteLine(gameBoardString);
        }
Ejemplo n.º 2
0
    public void calcNextMove(int player, GameBoardData gameBoard)
    {
        //Get valid turns and then choose one randomly
        List <int> validTurns = gameBoard.getValidTurns();

        turn = Random.Range(0, validTurns.Count - 1);
    }
        public static void Run()
        {
            bool isSuccessfulGuess = false;
            bool quitGame = false;
            ushort numberOfGuesses = UI.UIManager.GetNumberOfGuesses();
            GameBoardData gameBoard = new GameBoardData(numberOfGuesses);

            while (!quitGame && !isSuccessfulGuess && gameBoard.TurnsPlayed < numberOfGuesses)
            {
                UI.UIManager.DisplayBoard(gameBoard);
                BullsAndCows.IO.UserReply userReply = UI.UIManager.GetUserGuess();
                quitGame = userReply.QuitGame;

                if (!quitGame)
                {
                    Pin[] userPinsSequence = userReply.UserPinsSequence;
                    Turn newTurn = gameBoard.CompareUserGuess(userPinsSequence);
                    gameBoard.AddTurn(newTurn);
                    isSuccessfulGuess = newTurn.Results.CorrectInPlacePins == GProperties.PinsSequenceLength;
                }
            }

            if (!quitGame)
            {
                if(isSuccessfulGuess)
                {
                    UI.UIManager.NotifySuccess(gameBoard.TurnsPlayed);
                }
                else
                {
                    UI.UIManager.NotifyFailure(gameBoard.GoalSequence);
                }
            }
        }
Ejemplo n.º 4
0
        public GameBoardData GetGameBoardData()
        {
            GameBoardData data = new GameBoardData();

            data.step          = GameSettings.BoardStep;
            data.columnCount   = GameSettings.boardColCount;
            data.rowCount      = GameSettings.boardRowCount;
            data.evenCellColor = GameSettings.boardEvenCellColor;
            data.background    = GetBoardRendererData();
            data.cellData      = GetCellDataRenderer();
            return(data);
        }
Ejemplo n.º 5
0
    // Use this for initialization
    void Start()
    {
        boardData = getGameBoardData();

        input = new GameObject[boardRows * 2 + boardColumns * 2];

        isPreview = false;
        previousPreviewPosition = -1;

        initGameBoard();
        initGameBoardInput();
    }
Ejemplo n.º 6
0
    public void Load(GameBoardData data)
    {
        if (data != null && data.tiles != null)
        {
            SizeX = data.SizeX;
            SizeY = data.SizeY;

            for (int i = 0; i < data.tiles.Count; i++)
            {
                tiles[i] = data.tiles[i];
            }
        }
    }
Ejemplo n.º 7
0
    public GameBoardData getGameBoardData()
    {
        //TODO user have to define these values
        boardRows    = 7;
        boardColumns = 7;

        if (boardData == null)
        {
            boardData = new GameBoardData(boardRows, boardColumns);
        }

        return(boardData);
    }
Ejemplo n.º 8
0
    public void calcNextMove(int player, GameBoardData gameBoard)
    {
        countRatings = 0;

        board      = gameBoard;
        validTurns = board.getValidTurns();

        turnHighestRating = validTurns [0];
        highestRating     = int.MinValue;

        for (int i = 0; i < validTurns.Count; i++)
        {
            DeepSearch deepSearch = new DeepSearch(board, validTurns[i], deep, playerMe, playerMe, int.MinValue, int.MaxValue);
            deepSearch.setAiListener(this);
            deepSearch.Start();
        }
    }
Ejemplo n.º 9
0
    public void Initialize()
    {
        Input.multiTouchEnabled = false;
        Localer.Init();
        CreatePauseListener();
        GameData         = new GameData();
        Settings         = new ZPlayerSettings();
        AtlasFramesCache = new AtlasFramesCache();
        GameFlow         = new GameFlow();
        EventManager     = new EventManager();
        CurrentMenu      = UISetType.Global;
        // Feeding
        BoardData  = new GameBoardData();
        IAPManager = new ZIAPManager();

        ZAnalitycs.Initialize();
    }
Ejemplo n.º 10
0
    /**
     * Simulates all moves with the given deep and first insert position
     * and calculates a rating for this combination
     * @firstInsertPos has to be a valid insert position for the given GameBoard
     * @deep 1 is only the firstInsertPos move, 0 is no move
     * @playersTurn which player makes the next move
     * @playerMe which player is me. PlayerOne or PlayerTwo
     */
    public DeepSearch(GameBoardData board, int firstInsertPos, int deep, int playersTurn, int playerMe, int lowerBound, int upperBound)
    {
        this.deep        = deep;
        insertPosition   = firstInsertPos;
        this.board       = board.clone();
        this.playerMe    = playerMe;
        this.playersTurn = playersTurn;
        this.lowerBound  = lowerBound;
        this.upperBound  = upperBound;

        int singleWeight = 10, doubleWeight = 100, tripleWeight = 10000;

        weights     = new int[7];
        weights [0] = 0;
        weights [1] = singleWeight;
        weights [2] = doubleWeight;
        weights [3] = tripleWeight;
        weights [4] = tripleWeight * 10;
        weights [5] = tripleWeight * 100;
        weights [6] = tripleWeight * 1000;
    }
Ejemplo n.º 11
0
    // Use this for initialization
    void Start()
    {
        tutorial      = GetComponent <Tutorial> ();
        gameBoardData = gameBoardObject.getGameBoardData();

        winnerText = pauseCanvas.GetComponentInChildren <Text> ();

        if (MenuAttributes.vsKi)
        {
            if (MenuAttributes.difficulty == 1)
            {
                kiPlayer         = SECONDPLAYER;
                kiImplementation = new HardKI(SECONDPLAYER, 2);
                firstPlayerName  = MenuAttributes.firstPlayerName;
                secondPlayerName = kiImplementation.getName();
            }
            else if (MenuAttributes.difficulty == 2)
            {
                kiPlayer         = SECONDPLAYER;
                kiImplementation = new HardKI(SECONDPLAYER, 3);
                firstPlayerName  = MenuAttributes.firstPlayerName;
                secondPlayerName = kiImplementation.getName();
            }
            else
            {
                kiPlayer         = FIRSTPLAYER;
                kiImplementation = new HardKI(FIRSTPLAYER, 3);
                firstPlayerName  = kiImplementation.getName();
                secondPlayerName = MenuAttributes.firstPlayerName;
            }
        }
        else
        {
            kiPlayer         = NONE;
            firstPlayerName  = MenuAttributes.firstPlayerName;
            secondPlayerName = MenuAttributes.secondPlayerName;
        }

        restart();
    }
    void OnGUI()
    {
        GameBoard selectedObjectBoard = null;
        if (Selection.activeGameObject != null)
        {
            selectedObjectBoard = Selection.activeGameObject.GetComponent<GameBoard>();
        }

        EditorGUILayout.BeginHorizontal(); //BEGIN Whole Window

        //Sidebar
        EditorGUILayout.BeginVertical(GUILayout.Width(200)); // BEGIN Sidebar

        EditorGUILayout.BeginHorizontal(); // BEGIN Board Size

        currentData.SizeX = EditorGUILayout.IntField("Size X", currentData.SizeX);
        currentData.SizeY = EditorGUILayout.IntField("Size Y", currentData.SizeY);

        EditorGUILayout.EndHorizontal(); // END Board Size

        EditorGUILayout.Space();

        if (GUILayout.Button("Fill"))
        {
            currentData.Fill(selectedTile);
        }

        if (GUILayout.Button("Clear"))
        {
            currentData.Clear();
        }

        bool guiEnabled = GUI.enabled;
        GUI.enabled = selectedObjectBoard != null;

        if (GUILayout.Button("Save to Object"))
        {
            selectedObjectBoard.Load(currentData);
        }
        if (GUILayout.Button("Load From Object"))
        {
            currentData.Load(selectedObjectBoard);
        }

        GUI.enabled = guiEnabled;

        GUILayout.Space(30f);
        fileName = EditorGUILayout.TextField("File:", fileName);

        if (GUILayout.Button("Save to File"))
        {
            FileHelper.writeObjectFile(filePrefix + fileName, currentData, FileHelper.SerializeXML);
        }

        GUI.enabled = FileHelper.fileExists(filePrefix + fileName);

        if (GUILayout.Button("Load from File"))
        {
            currentData = FileHelper.readObjectFile<GameBoardData>(filePrefix + fileName, FileHelper.DeserializeXML<GameBoardData>);
        }

        GUI.enabled = guiEnabled;

        EditorGUILayout.EndVertical(); // END Sidebar

        //Board Editor
        EditorGUILayout.BeginVertical(); // BEGIN Board Editor

        EditorGUILayout.BeginHorizontal(); // BEGIN selectedTile Menu
        foreach (GameBoardTile tile in Enum.GetValues(typeof(GameBoardTile)))
        {
            if (GUILayout.Button(tile.ToString(), (tile == selectedTile ? selectedButton : GUI.skin.button)))
            {
                selectedTile = tile;
            }
        }
        EditorGUILayout.EndHorizontal(); // END selectedTile Menu

        EditorGUILayout.BeginHorizontal(); // BEGIN Board Layout

        #region V2 Code
        /*
        EditorGUILayout.BeginVertical(); // BEGIN Row Fill Column
        GUILayout.Space(20);
        for (int y = 0; y < currentData.SizeY; y++)
        {
            if (GUILayout.Button(">", GUILayout.Width(20), GUILayout.Height(50)))
            {
                currentData.FillRow(y, selectedTile);
            }
        }
        EditorGUILayout.EndVertical(); // END Row Fill Column
         */
        #endregion

        for (int x = 0; x < currentData.SizeX; x++)
        {

            EditorGUILayout.BeginVertical(); // BEGIN Sub-Board Layout

            #region V2 Code
            /*
            if (GUILayout.Button("v", GUILayout.Width(50), GUILayout.Height(20)))
            {
                currentData.FillColumn(x, selectedTile);
            }
            */
            #endregion

            for (int y = 0; y < currentData.SizeY; y++)
            {
                if (GUILayout.Button(currentData.GetTileValue(x, y).ToString(), GUILayout.Width(50), GUILayout.Height(50)))
                {
                    currentData.SetTileValue(x, y, selectedTile);
                }
            }
            EditorGUILayout.EndVertical(); // END Sub-Board Layout
        }
        EditorGUILayout.EndHorizontal(); // END Board Layout

        EditorGUILayout.EndVertical(); //END Board Editor

        EditorGUILayout.EndHorizontal(); //END Whole Window
    }
Ejemplo n.º 13
0
    public int calculateWinner(GameBoardData gameBoard)
    {
        GridElementData[ , ] board = gameBoard.getGameBoard();
        int rows    = gameBoard.boardRows;
        int columns = gameBoard.boardColumns;

        int  column, row, prev, count, playerAtField, rowCounter;
        bool firstPlayerWon  = false;
        bool secondPlayerWon = false;

        //check rows
        for (column = 0; column < columns; column++)
        {
            count = 1;
            prev  = 0;
            for (row = 0; row < rows; row++)
            {
                playerAtField = board[row, column].player;
                if (playerAtField != prev)
                {
                    prev  = playerAtField;
                    count = 1;
                }
                else if (playerAtField == GameManager.FIRSTPLAYER)                    //first player
                {
                    count++;
                    if (count >= GameManager.tokensToWin)
                    {
                        firstPlayerWon = true;
                    }
                }
                else if (playerAtField == GameManager.SECONDPLAYER)                    //second player
                {
                    count++;
                    if (count >= GameManager.tokensToWin)
                    {
                        secondPlayerWon = true;
                    }
                }
            }
        }

        //check columns
        for (row = 0; row < rows; row++)
        {
            count = 1;
            prev  = 0;
            for (column = 0; column < columns; column++)
            {
                playerAtField = board[row, column].player;
                if (playerAtField != prev)
                {
                    prev  = playerAtField;
                    count = 1;
                }
                else if (playerAtField == GameManager.FIRSTPLAYER)                    //first player
                {
                    count++;
                    if (count >= GameManager.tokensToWin)
                    {
                        firstPlayerWon = true;
                    }
                }
                else if (playerAtField == GameManager.SECONDPLAYER)                    //second player
                {
                    count++;
                    if (count >= GameManager.tokensToWin)
                    {
                        secondPlayerWon = true;
                    }
                }
            }
        }

        //check diagonal
        for (column = 0; column < columns; column++)
        {
            count      = 1;
            prev       = GameManager.NONE;
            rowCounter = 0;
            while (column + rowCounter < columns && rowCounter < rows)
            {
                playerAtField = board[rowCounter, column + rowCounter].player;
                if (playerAtField != prev)
                {
                    prev  = playerAtField;
                    count = 1;
                }
                else if (playerAtField == GameManager.FIRSTPLAYER)                    //first player
                {
                    count++;
                    if (count >= GameManager.tokensToWin)
                    {
                        firstPlayerWon = true;
                    }
                }
                else if (playerAtField == GameManager.SECONDPLAYER)                    //second player
                {
                    count++;
                    if (count >= GameManager.tokensToWin)
                    {
                        secondPlayerWon = true;
                    }
                }

                rowCounter++;
            }
        }
        for (row = 0; row < rows; row++)
        {
            count      = 1;
            prev       = 0;
            rowCounter = 0;
            while (row + rowCounter < rows && rowCounter < columns)
            {
                playerAtField = board[row + rowCounter, rowCounter].player;
                if (playerAtField != prev)
                {
                    prev  = playerAtField;
                    count = 1;
                }
                else if (playerAtField == GameManager.FIRSTPLAYER)                    //first player
                {
                    count++;
                    if (count >= GameManager.tokensToWin)
                    {
                        firstPlayerWon = true;
                    }
                }
                else if (playerAtField == GameManager.SECONDPLAYER)                    //second player
                {
                    count++;
                    if (count >= GameManager.tokensToWin)
                    {
                        secondPlayerWon = true;
                    }
                }

                rowCounter++;
            }
        }

        for (column = 0; column < columns; column++)
        {
            count      = 1;
            prev       = 0;
            rowCounter = 0;
            while (column - rowCounter >= 0 && rowCounter < rows)
            {
                playerAtField = board[rowCounter, column - rowCounter].player;
                if (playerAtField != prev)
                {
                    prev  = playerAtField;
                    count = 1;
                }
                else if (playerAtField == GameManager.FIRSTPLAYER)                    //first player
                {
                    count++;
                    if (count >= GameManager.tokensToWin)
                    {
                        firstPlayerWon = true;
                    }
                }
                else if (playerAtField == GameManager.SECONDPLAYER)                    //second player
                {
                    count++;
                    if (count >= GameManager.tokensToWin)
                    {
                        secondPlayerWon = true;
                    }
                }

                rowCounter++;
            }
        }
        for (row = 0; row < rows; row++)
        {
            count      = 1;
            prev       = 0;
            rowCounter = 0;
            while (row - rowCounter >= 0 && rowCounter < columns)
            {
                playerAtField = board[row - rowCounter, rowCounter].player;
                if (playerAtField != prev)
                {
                    prev  = playerAtField;
                    count = 1;
                }
                else if (playerAtField == GameManager.FIRSTPLAYER)                    //first player
                {
                    count++;
                    if (count >= GameManager.tokensToWin)
                    {
                        firstPlayerWon = true;
                    }
                }
                else if (playerAtField == GameManager.SECONDPLAYER)                    //second player
                {
                    count++;
                    if (count >= GameManager.tokensToWin)
                    {
                        secondPlayerWon = true;
                    }
                }

                rowCounter++;
            }
        }

        if (!movePossible() || (firstPlayerWon && secondPlayerWon))
        {
            return(GameManager.DRAW);
        }
        else if (firstPlayerWon)
        {
            return(GameManager.FIRSTPLAYER);
        }
        else if (secondPlayerWon)
        {
            return(GameManager.SECONDPLAYER);
        }
        else
        {
            return(GameManager.NONE);
        }
    }
    public void Load(GameBoardData data)
    {
        if (data != null && data.tiles != null)
        {
            SizeX = data.SizeX;
            SizeY = data.SizeY;

            for (int i = 0; i < data.tiles.Count; i++)
            {
                tiles[i] = data.tiles[i];
            }
        }
    }
Ejemplo n.º 15
0
    void OnGUI()
    {
        GameBoard selectedObjectBoard = null;

        if (Selection.activeGameObject != null)
        {
            selectedObjectBoard = Selection.activeGameObject.GetComponent <GameBoard>();
        }

        EditorGUILayout.BeginHorizontal(); //BEGIN Whole Window

        //Sidebar
        EditorGUILayout.BeginVertical(GUILayout.Width(200)); // BEGIN Sidebar

        EditorGUILayout.BeginHorizontal();                   // BEGIN Board Size

        currentData.SizeX = EditorGUILayout.IntField("Size X", currentData.SizeX);
        currentData.SizeY = EditorGUILayout.IntField("Size Y", currentData.SizeY);

        EditorGUILayout.EndHorizontal(); // END Board Size

        EditorGUILayout.Space();

        if (GUILayout.Button("Fill"))
        {
            currentData.Fill(selectedTile);
        }

        if (GUILayout.Button("Clear"))
        {
            currentData.Clear();
        }

        bool guiEnabled = GUI.enabled;

        GUI.enabled = selectedObjectBoard != null;

        if (GUILayout.Button("Save to Object"))
        {
            selectedObjectBoard.Load(currentData);
        }
        if (GUILayout.Button("Load From Object"))
        {
            currentData.Load(selectedObjectBoard);
        }

        GUI.enabled = guiEnabled;

        GUILayout.Space(30f);
        fileName = EditorGUILayout.TextField("File:", fileName);

        if (GUILayout.Button("Save to File"))
        {
            FileHelper.writeObjectFile(filePrefix + fileName, currentData, FileHelper.SerializeXML);
        }

        GUI.enabled = FileHelper.fileExists(filePrefix + fileName);

        if (GUILayout.Button("Load from File"))
        {
            currentData = FileHelper.readObjectFile <GameBoardData>(filePrefix + fileName, FileHelper.DeserializeXML <GameBoardData>);
        }

        GUI.enabled = guiEnabled;

        EditorGUILayout.EndVertical(); // END Sidebar

        //Board Editor
        EditorGUILayout.BeginVertical();   // BEGIN Board Editor

        EditorGUILayout.BeginHorizontal(); // BEGIN selectedTile Menu
        foreach (GameBoardTile tile in Enum.GetValues(typeof(GameBoardTile)))
        {
            if (GUILayout.Button(tile.ToString(), (tile == selectedTile ? selectedButton : GUI.skin.button)))
            {
                selectedTile = tile;
            }
        }
        EditorGUILayout.EndHorizontal();   // END selectedTile Menu

        EditorGUILayout.BeginHorizontal(); // BEGIN Board Layout

        #region V2 Code

        /*
         * EditorGUILayout.BeginVertical(); // BEGIN Row Fill Column
         * GUILayout.Space(20);
         * for (int y = 0; y < currentData.SizeY; y++)
         * {
         *  if (GUILayout.Button(">", GUILayout.Width(20), GUILayout.Height(50)))
         *  {
         *      currentData.FillRow(y, selectedTile);
         *  }
         * }
         * EditorGUILayout.EndVertical(); // END Row Fill Column
         */
        #endregion

        for (int x = 0; x < currentData.SizeX; x++)
        {
            EditorGUILayout.BeginVertical(); // BEGIN Sub-Board Layout

            #region V2 Code

            /*
             * if (GUILayout.Button("v", GUILayout.Width(50), GUILayout.Height(20)))
             * {
             *  currentData.FillColumn(x, selectedTile);
             * }
             */
            #endregion

            for (int y = 0; y < currentData.SizeY; y++)
            {
                if (GUILayout.Button(currentData.GetTileValue(x, y).ToString(), GUILayout.Width(50), GUILayout.Height(50)))
                {
                    currentData.SetTileValue(x, y, selectedTile);
                }
            }
            EditorGUILayout.EndVertical(); // END Sub-Board Layout
        }
        EditorGUILayout.EndHorizontal();   // END Board Layout

        EditorGUILayout.EndVertical();     //END Board Editor

        EditorGUILayout.EndHorizontal();   //END Whole Window
    }