Esempio n. 1
0
 private void FillBoard()
 {
     foreach (Checkers.Piece wp in currentGame.WhitePieces)
     {
         if (wp.Type == Type.KING)
         {
             SpawnPiece(wp.Cell.R, wp.Cell.C, whiteKing);
         }
         else
         {
             SpawnPiece(wp.Cell.R, wp.Cell.C, whitePiece);
         }
     }
     foreach (Checkers.Piece wp in currentGame.BlackPieces)
     {
         if (wp.Type == Type.KING)
         {
             SpawnPiece(wp.Cell.R, wp.Cell.C, blackKing);
         }
         else
         {
             SpawnPiece(wp.Cell.R, wp.Cell.C, blackPiece);
         }
     }
     if (currentGame.CurrentTurn == 1)
     {
         PT = playerTurn.BLACK;
     }
     else
     {
         PT = playerTurn.WHITE;
     }
 }
Esempio n. 2
0
        private void GameForm_MouseClick(object sender, MouseEventArgs e)
        {
            if (this._environment.turn == playerTurn.playerRed)
            {
                int colIndex = this.getColumnNumber(e.Location);
                if (colIndex != -1)
                {
                    int rowIndex = this._environment.getTheLowestEmptyCellIndexInCol(colIndex);
                    if (rowIndex != -1)
                    {
                        //this.board[rowIndex, colIndex] = (this._turn==playerTurn.playerRed) ? 1 : 2; //add in board the piece
                        this._environment.setCaseNewState(colIndex, rowIndex, (this._environment.turn == playerTurn.playerRed) ? caseState.red : caseState.yellow);
                        //DrawPawn(colIndex, rowIndex);
                        //check if someone has won
                        this._environment.nbMovePlayed++;
                        playerTurn winner = getWinner(this._environment.turn);
                        if (winner != playerTurn.none)
                        {
                            this._environment.restartGame(winner);
                        }

                        //if nobody has won we give the other player the turn
                        if (this._environment.turn == playerTurn.playerRed)
                        {
                            this._environment.turn = playerTurn.playerYellow;
                        }
                        else if (this._environment.turn == playerTurn.playerYellow)
                        {
                            this._environment.turn = playerTurn.playerRed;
                        }
                        this._environment.IsTurnAgent = true;
                    }
                }
            }
        }
Esempio n. 3
0
 public void changeTurn()
 {
     if (Character.activeCharacter != null)
     {
         Character.activeCharacter.transform.SendMessage("setIdle");
         Character.activeCharacter = null;
     }
     activePlayer.SendMessage("disableActivePlayer");
     if (turn == playerTurn.player1)
     {
         turn             = playerTurn.player2;
         textGiliran.text = "Player 2";
         activePlayer     = pemain2;
         // Pemain1.GetComponentInChildren<BoxCollider2D>().enabled = false;
         // Pemain2.GetComponentInChildren<BoxCollider2D>().enabled = true;
     }
     else if (turn == playerTurn.player2)
     {
         turn             = playerTurn.player1;
         textGiliran.text = "Player 1";
         activePlayer     = pemain1;
     }
     activePlayer.SendMessage("enableActivePlayer");
     Grids.grid.SendMessage("decoloringEveryTile");
     // GameObject textOnPanel = playerTurnPanel.Find("Turn Text");
     // Text textTurn = textOnPanel.GetComponent<Text>();
     // textTurn = textGiliran;
     textGiliranOnPanel.text = "giliran " + textGiliran.text;
     playerTurnPanel.SetActive(true);
     StartCoroutine("activateTurnPanel");
 }
Esempio n. 4
0
    public void TurnEnded()
    {
        overviewCam.SetActive(true);
        if (CheckIfWon())
        {
            return;
        }
        deathObject.Play("Death");
        gameState = currentState.Picking;
        Instantiate(powerups[Random.Range(0, powerups.Length)], spawnlocations[Random.Range(0, spawnlocations.Length)]);
        switch (currentPlayer)
        {
        case playerTurn.RedTeam:
            currentPlayer      = playerTurn.BlueTeam;
            whoseTurnText.text = "Blue Player Turn";
            break;

        case playerTurn.BlueTeam:
            currentPlayer      = playerTurn.RedTeam;
            whoseTurnText.text = "Red Player Turn";
            break;

        default:
            break;
        }
    }
Esempio n. 5
0
        public playerTurn getWinner(playerTurn playerToCheck)
        {
            #region vertical win check(|)
            //vertical win check
            for (int row = 0; row < Grid.Count - 3; row++)
            {
                for (int col = 0; col < Grid[0].Count; col++)
                {
                    if (this.allStateCaseAreEqual(playerToCheck, Grid[row][col], Grid[row + 1][col], Grid[row + 2][col], Grid[row + 3][col]))
                    {
                        return(playerToCheck);
                    }
                }
            }
            #endregion

            #region horizontal win check (-)

            //horizontal win check
            for (int row = 0; row < Grid.Count; row++)
            {
                for (int col = 0; col < Grid[0].Count - 3; col++)
                {
                    if (this.allStateCaseAreEqual(playerToCheck, Grid[row][col], Grid[row][col + 1], Grid[row][col + 2], Grid[row][col + 3]))
                    {
                        return(playerToCheck);
                    }
                }
            }
            #endregion

            #region top left diagonal win check (\)
            for (int row = 0; row < Grid.Count - 3; row++)
            {
                for (int col = 0; col < Grid[0].Count - 3; col++)
                {
                    if (this.allStateCaseAreEqual(playerToCheck, Grid[row][col], Grid[row + 1][col + 1], Grid[row + 2][col + 2], Grid[row + 3][col + 3]))
                    {
                        return(playerToCheck);
                    }
                }
            }
            #endregion

            #region top right diagonal win check (/)
            //top right diagonal win check (/)
            for (int row = 0; row < Grid.Count - 3; row++)
            {
                for (int col = 3; col < Grid[0].Count; col++)
                {
                    if (this.allStateCaseAreEqual(playerToCheck, Grid[row][col], Grid[row + 1][col - 1], Grid[row + 2][col - 2], Grid[row + 3][col - 3]))
                    {
                        return(playerToCheck);
                    }
                }
            }
            #endregion
            return(playerTurn.none);
        }
Esempio n. 6
0
        public void printWinner(playerTurn player)
        {
            string messagePlayerWon = (player == playerTurn.playerRed) ? "Red" : "Yellow";

            MessageBox.Show("Congrulation " + messagePlayerWon + " player ! You Have Won ! ");
            //Application.Restart();
            Environment.Exit(0);
        }
    public bool Move(bool isHuman)
    {
        playerTurn player = this.GetComponentInParent <playerTurn>();

        //  StartCoroutine(waitForInput());
        //Debug.Log("moving");
        player.playerPhase(isHuman);
        return(true);
    }
Esempio n. 8
0
    Quaternion getSideRotate(playerTurn side)
    {
        if (side == playerTurn.RED)
        {
            return(Quaternion.Euler(0, 0, 180));
        }

        return(Quaternion.identity);
    }
Esempio n. 9
0
    void updatePieceSide(GameObject piece, Position pos, playerTurn side)
    {
        PiecesClass gManScript = piece.GetComponent <PiecesClass>();

        gManScript.side = side;
        Position previousPos = gManScript.positionOB;

        gManScript.positionOB = pos;
    }
Esempio n. 10
0
    void updatePieceSide(PiecesClass piece, Position pos, playerTurn side)
    {
        piece.side = side;
        Position previousPos = piece.positionOB;

        piece.positionOB        = pos;
        currentPos[pos]         = piece.gameObject;
        currentPos[previousPos] = null;
    }
Esempio n. 11
0
 void changeTurn()
 {
     if (currentPlayer == playerTurn.GREEN)
     {
         currentPlayer = playerTurn.RED;
     }
     else if (currentPlayer == playerTurn.RED)
     {
         currentPlayer = playerTurn.GREEN;
     }
 }
Esempio n. 12
0
 public void updateWinnerText(playerTurn winner)
 {
     if (gm.currentPlayer == playerTurn.GREEN)
     {
         updateVicText("GREEN");
     }
     else if (gm.currentPlayer == playerTurn.RED)
     {
         updateVicText("RED");
     }
 }
Esempio n. 13
0
        //Cette fonction vide le puissance 4
        public void restartGame(playerTurn winner)
        {
            for (int j = 0; j < 6; j++)
            {
                for (int i = 0; i < 7; i++)
                {
                    _grid[j][i].State = caseState.empty;
                }
            }

            ui.printWinner(winner);
        }
Esempio n. 14
0
    void win(playerTurn winner)
    {
        if (winner == playerTurn.GREEN)
        {
            Debug.Log("GREEN WINS");
        }
        else
        {
            Debug.Log("RED WINS");
        }

        endGame();
    }
Esempio n. 15
0
        public bool allStateCaseAreEqual(playerTurn toCheck, params Case[] cases)
        {
            caseState stateToCheck = (toCheck == playerTurn.playerRed) ? caseState.red : caseState.yellow;

            foreach (Case c in cases)
            {
                if (c.State != stateToCheck)
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 16
0
    GameObject createPieceMidGame(GameObject piece, Position pos, playerTurn side)
    {
        GameObject gMan = (GameObject)Instantiate(piece, posTransforms[pos], getSideRotate(side));

        gMan.name       = side.ToString() + piece.GetComponent <PiecesClass>().type;
        currentPos[pos] = gMan;

        PiecesClass gManScript = piece.GetComponent <PiecesClass>();

        gManScript.gm = this;

        return(gMan);
    }
Esempio n. 17
0
    void createPiece(GameObject piece, Position pos, playerTurn side)
    {
        GameObject gMan = (GameObject)Instantiate(piece, posTransforms[pos], getSideRotate(side));

        gMan.name = side.ToString() + piece.GetComponent <PiecesClass>().type;
        currentPos.Add(pos, gMan);

        PiecesClass gManScript = piece.GetComponent <PiecesClass>();

        gManScript.gm = this;

        Debug.Log(gManScript.side.ToString() + " " + gManScript.type + " at " + gManScript.positionOB.ToString() + " " + gMan.transform.position);
    }
Esempio n. 18
0
    void takePieceCurrentlyIn(Position pos)
    {
        GameObject  takenPiece  = currentPos[pos];
        PiecesClass takenScript = takenPiece.GetComponent <PiecesClass>();

        if (takenScript.type == "King")
        {
            winSide = currentPlayer; //current player so=hould be the oppsite to the taken piece
            winFlag = true;
        }
        else if (takenScript.type == "Lord")
        {
            takenPiece  = turnLordToMan(takenPiece);
            takenScript = takenPiece.GetComponent <PiecesClass>();
        }

        if (takenScript.side == playerTurn.RED)
        {
            //TAKEN BY GREEN
            takenScript.side = playerTurn.GREEN;
            for (int i = 0; i < greenTaken.Length; i++)
            {
                if (greenTaken[i] == null)
                {
                    greenTaken[i] = takenPiece;
                    takenPiece.transform.position = new Vector3(-5 + (2 * i), -6);
                    takenPiece.transform.rotation = getSideRotate(playerTurn.GREEN);
                    currentPos[pos] = null;
                    takenScript.updateLocation(Position.TAKEN);
                    break;
                }
            }
        }
        else if (takenScript.side == playerTurn.GREEN)
        {
            //TAKEN BY RED
            takenScript.side = playerTurn.RED;
            for (int i = 0; i < redTaken.Length; i++)
            {
                if (redTaken[i] == null)
                {
                    redTaken[i] = takenPiece;
                    takenPiece.transform.position = new Vector3(-5 + (2 * i), 6);
                    takenPiece.transform.rotation = getSideRotate(playerTurn.RED);
                    currentPos[pos] = null;
                    takenScript.updateLocation(Position.TAKEN);
                    break;
                }
            }
        }
    }
 void switchPlayerTurn()
 {
     if (currentTurn == playerTurn.P1)
     {
         currentTurn = playerTurn.P2;
         turn        = 2;
         xo          = "o";
     }
     else if (currentTurn == playerTurn.P2)
     {
         currentTurn = playerTurn.P1;
         turn        = 1;
         xo          = "x";
     }
 }
Esempio n. 20
0
    public void startGame()
    {
        currentPlayer = playerTurn.GREEN;
        clearBoard();
        //clear array AND reset variables
        winFlag    = false;
        playable   = true;
        currentPos = new Dictionary <Position, GameObject>();
        //Load all the pieces in the correct places
        createPiece(manPiece, Position.BC, playerTurn.GREEN);
        createPiece(ministerPiece, Position.GL, playerTurn.GREEN);
        createPiece(generalPiece, Position.GR, playerTurn.GREEN);

        GameObject tempGK = createPieceMidGame(kingPiece, Position.GC, playerTurn.GREEN);

        greenKing = tempGK.GetComponent <PiecesClass>();

        createPiece(manPiece, Position.TC, playerTurn.RED);
        createPiece(ministerPiece, Position.RR, playerTurn.RED);
        createPiece(generalPiece, Position.RL, playerTurn.RED);

        GameObject tempRK = createPieceMidGame(kingPiece, Position.RC, playerTurn.RED);

        redKing = tempRK.GetComponent <PiecesClass>();

        currentPos.Add(Position.BL, null);
        currentPos.Add(Position.BR, null);
        currentPos.Add(Position.TL, null);
        currentPos.Add(Position.TR, null);

        foreach (KeyValuePair <Position, GameObject> entry in currentPos)
        {
            if (entry.Value != null)
            {
                //Debug.Log(entry.Key.ToString() +" "+ entry.Value.name+" "+ entry.Value.GetComponent<PiecesClass>().side.ToString());
                if (entry.Value.name.Contains("GREEN"))
                {
                    updatePieceSide(entry.Value, entry.Key, playerTurn.GREEN);
                }
                else if (entry.Value.name.Contains("RED"))
                {
                    updatePieceSide(entry.Value, entry.Key, playerTurn.RED);
                }
            }
        }
    }
Esempio n. 21
0
    private void UpdateMousePointer()
    {
        if (!Camera.main)
        {
            return;
        }
        RaycastHit hit;

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
        {
            if (currentGame.CurrentTurn == 1)
            {
                playerColor = playerTurn.WHITE;
            }
            else
            {
                playerColor = playerTurn.BLACK;
            }
            if (playerColor == playerTurn.WHITE)
            {
                if (hit.transform.tag == "WhitePiece" || hit.transform.tag == "Board")
                {
                    mousePointer = new Vector2(hit.point.x, hit.point.z);
                }
                else
                {
                    mousePointer = new Vector2(-10.0f, -10.0f);
                }
            }
            else if (playerColor == playerTurn.BLACK)
            {
                if (hit.transform.tag == "BlackPiece" || hit.transform.tag == "Board")
                {
                    mousePointer = new Vector2(hit.point.x, hit.point.z);
                }
                else
                {
                    mousePointer = new Vector2(-10.0f, -10.0f);
                }
            }
        }
    }
Esempio n. 22
0
    GameObject[] greenTaken = new GameObject[6]; //-6



    // Start is called before the first frame update
    void Start()
    {
        posTransforms.Add(Position.GL, new Vector3(-2, -3, 0));
        posTransforms.Add(Position.GC, new Vector3(0, -3, 0));
        posTransforms.Add(Position.GR, new Vector3(2, -3, 0));

        posTransforms.Add(Position.BL, new Vector3(-2, -1, 0));
        posTransforms.Add(Position.BC, new Vector3(0, -1, 0));
        posTransforms.Add(Position.BR, new Vector3(2, -1, 0));

        posTransforms.Add(Position.TL, new Vector3(-2, 1, 0));
        posTransforms.Add(Position.TC, new Vector3(0, 1, 0));
        posTransforms.Add(Position.TR, new Vector3(2, 1, 0));

        posTransforms.Add(Position.RL, new Vector3(-2, 3, 0));
        posTransforms.Add(Position.RC, new Vector3(0, 3, 0));
        posTransforms.Add(Position.RR, new Vector3(2, 3, 0));


        currentPlayer = playerTurn.GREEN;
    }
Esempio n. 23
0
        public bool isAWinningMove(int col, playerTurn turn)
        {
            caseState stateToCheck            = (turn == playerTurn.playerRed) ? caseState.red : caseState.yellow;
            int       rowIndexOfLastPawnInCol = this._environment.getTheLowestEmptyCellIndexInCol(col);

            // There is a winning move with columns ?
            if (rowIndexOfLastPawnInCol < 3 &&
                this._environment.Grid[rowIndexOfLastPawnInCol + 1][col].State == stateToCheck &&
                this._environment.Grid[rowIndexOfLastPawnInCol + 2][col].State == stateToCheck &&
                this._environment.Grid[rowIndexOfLastPawnInCol + 3][col].State == stateToCheck)
            {
                return(true);
            }

            // There is a winning move with line ?
            int nbYellowAtRight = 0;
            int nbYellowAtLeft  = 0;

            for (int i = 1; col + i < this._environment.Width; i++)
            {
                if (this._environment.Grid[rowIndexOfLastPawnInCol][col + i].State == stateToCheck)
                {
                    nbYellowAtRight++;
                }
                else
                {
                    break;
                }
            }
            for (int i = 1; col - i >= 0; i++)
            {
                if (this._environment.Grid[rowIndexOfLastPawnInCol][col - i].State == stateToCheck)
                {
                    nbYellowAtLeft++;
                }
                else
                {
                    break;
                }
            }
            if (nbYellowAtLeft >= 3 || nbYellowAtRight >= 3 || nbYellowAtLeft + nbYellowAtRight >= 3)
            {
                return(true);
            }

            // There is a winning move with diagonal up-right?
            nbYellowAtRight = 0;
            nbYellowAtLeft  = 0;
            for (int i = 1; col + i < this._environment.Width && rowIndexOfLastPawnInCol - i >= 0; i++)
            {
                if (this._environment.Grid[rowIndexOfLastPawnInCol - i][col + i].State == stateToCheck)
                {
                    nbYellowAtRight++;
                }
                else
                {
                    break;
                }
            }
            for (int i = 1; col - i >= 0 && rowIndexOfLastPawnInCol + i < this._environment.Height; i++)
            {
                if (this._environment.Grid[rowIndexOfLastPawnInCol + i][col - i].State == stateToCheck)
                {
                    nbYellowAtLeft++;
                }
                else
                {
                    break;
                }
            }
            if (nbYellowAtLeft >= 3 || nbYellowAtRight >= 3 || nbYellowAtLeft + nbYellowAtRight >= 3)
            {
                return(true);
            }

            // There is a winning move with diagonal up-left?
            nbYellowAtRight = 0;
            nbYellowAtLeft  = 0;
            for (int i = 1; col - i >= 0 && rowIndexOfLastPawnInCol - i >= 0; i++)
            {
                if (this._environment.Grid[rowIndexOfLastPawnInCol - i][col - i].State == stateToCheck)
                {
                    nbYellowAtLeft++;
                }
                else
                {
                    break;
                }
            }
            for (int i = 1; (col + i) < this._environment.Width && (rowIndexOfLastPawnInCol + i) < this._environment.Height; i++)
            {
                if (this._environment.Grid[rowIndexOfLastPawnInCol + i][col + i].State == stateToCheck)
                {
                    nbYellowAtRight++;
                }
                else
                {
                    break;
                }
            }
            if (nbYellowAtLeft >= 3 || nbYellowAtRight >= 3 || nbYellowAtLeft + nbYellowAtRight >= 3)
            {
                return(true);
            }

            // if there is no winning move
            return(false);
        }
Esempio n. 24
0
 public void SetTurn(playerTurn p)
 {
     this.PT = p;
 }
Esempio n. 25
0
        //implémentation de negaMax, une amélioration de min max avec de l'élagage aplha Beta
        public int negaMax(playerTurn turn, int alpha, int beta, ref int bestColToPlay, int depth)
        {
            int bestScore = -int.MaxValue;

            if (_beliefs.environment.nbMovePlayed == _beliefs.environment.Height * _beliefs.environment.Width)
            {
                return(0);
            }


            if (depth <= 0)
            {
                bestScore = eval(turn);
                return(bestScore);
            }
            else
            {
                List <int> columns = new List <int>()
                {
                    0, 1, 2, 3, 4, 5, 6
                };
                //shuffle col numbers
                columns.shuffle();
                foreach (int x in columns) // compute the score of all possible next move and keep the best one
                {
                    if (this.captor.canPlay(x))
                    {
                        if (this._beliefs.environment.Grid[this._beliefs.environment.getTheLowestEmptyCellIndexInCol(x)][x].State == caseState.empty)
                        {
                            caseState state = (turn == playerTurn.playerRed) ? caseState.red : caseState.yellow;
                            int       row   = this._beliefs.environment.getTheLowestEmptyCellIndexInCol(x);
                            this._beliefs.environment.Grid[row][x].State = state;
                            this._beliefs.environment.nbMovePlayed++;

                            int nextBestColToPlay = 3;
                            //depth--;
                            int score = -negaMax(playerTurn.playerRed, -beta, -alpha, ref nextBestColToPlay, depth--);

                            this._beliefs.environment.Grid[row][x].State = caseState.empty;
                            this._beliefs.environment.nbMovePlayed--;

                            if (score > bestScore)
                            {
                                bestScore     = score;
                                bestColToPlay = x;
                            }
                            if (score > alpha)
                            {
                                alpha         = bestScore;
                                bestColToPlay = x;
                                if (alpha > beta)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            return(bestScore);
        }
Esempio n. 26
0
        //fonction d'évaluation
        public int eval(playerTurn player)
        {
            caseState  statePlayer      = (player == playerTurn.playerRed) ? caseState.red : caseState.yellow;
            playerTurn otherPlayer      = (player == playerTurn.playerRed) ? playerTurn.playerYellow : playerTurn.playerRed;
            caseState  stateOtherPlayer = (otherPlayer == playerTurn.playerRed) ? caseState.red : caseState.yellow;
            //score eval
            int score = 1, cpt = 0;

            if (this._beliefs.environment.getWinner(otherPlayer) == otherPlayer)
            {
                return(-10000 + this._beliefs.environment.nbMovePlayed);
            }
            else if (this._beliefs.environment.getWinner(player) == player)
            {
                return(10000 - this._beliefs.environment.nbMovePlayed);
            }
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    if (this._beliefs.environment.Grid[i][j].State == caseState.empty)
                    {
                        continue;
                    }
                    //Colonnes

                    if (i > 3)
                    {
                        if (this._beliefs.environment.Grid[i][j].State == statePlayer)
                        {
                            ++cpt;

                            while (this._beliefs.environment.Grid[i - cpt][j].State == statePlayer)
                            {
                                ++cpt;
                            }
                            if (this._beliefs.environment.Grid[i - cpt - 1][j].State != stateOtherPlayer)
                            {
                                if (cpt == 3)
                                {
                                    score += 1000;
                                }
                                else if (cpt == 2)
                                {
                                    score += 100;
                                }
                                else
                                {
                                    score += 10;
                                }
                            }
                            cpt = 0;
                        }
                        else if (this._beliefs.environment.Grid[i][j].State == stateOtherPlayer)
                        {
                            ++cpt;

                            while (this._beliefs.environment.Grid[i - cpt][j].State == stateOtherPlayer)
                            {
                                ++cpt;
                            }
                            if (this._beliefs.environment.Grid[i - cpt - 1][j].State != statePlayer)
                            {
                                if (cpt == 3)
                                {
                                    score -= 1000;
                                }
                                else if (cpt == 2)
                                {
                                    score -= 100;
                                }
                                else
                                {
                                    score -= 10;
                                }
                            }
                            cpt = 0;
                        }
                    }
                    // Amelioration à apporter : ne scanne pas les 3 cases à gauche
                    //Lignes
                    if (j < 3)
                    {
                        if (this._beliefs.environment.Grid[i][j].State == statePlayer)
                        {
                            ++cpt;

                            while (this._beliefs.environment.Grid[i][j + cpt].State == statePlayer)
                            {
                                ++cpt;
                            }
                            if (i != 0)
                            {
                                if (this._beliefs.environment.Grid[i][j + cpt + 1].State != stateOtherPlayer)
                                {
                                    if (cpt == 3)
                                    {
                                        score += 1000;
                                    }
                                    else if (cpt == 2)
                                    {
                                        score += 100;
                                    }
                                    else
                                    {
                                        score += 10;
                                    }
                                }
                            }
                            else
                            {
                                if (j != 0)
                                {
                                    if (this._beliefs.environment.Grid[i][j + cpt + 1].State != stateOtherPlayer || this._beliefs.environment.Grid[i][j - 1].State != stateOtherPlayer)
                                    {
                                        if (cpt == 3)
                                        {
                                            score += 1000;
                                        }
                                        else if (cpt == 2)
                                        {
                                            score += 100;
                                        }
                                        else
                                        {
                                            score += 10;
                                        }
                                    }
                                    else
                                    {
                                        if (this._beliefs.environment.Grid[i][j + cpt + 1].State != stateOtherPlayer)
                                        {
                                            if (cpt == 3)
                                            {
                                                score += 1000;
                                            }
                                            else if (cpt == 2)
                                            {
                                                score += 100;
                                            }
                                            else
                                            {
                                                score += 10;
                                            }
                                        }
                                    }
                                }
                            }
                            cpt = 0;
                        }
                        else if (this._beliefs.environment.Grid[i][j].State == stateOtherPlayer)
                        {
                            ++cpt;

                            while (this._beliefs.environment.Grid[i][j + cpt].State == stateOtherPlayer)
                            {
                                ++cpt;
                            }

                            if (i != 0)
                            {
                                if (j + cpt + 1 < 7 && this._beliefs.environment.Grid[i][j + cpt + 1].State != statePlayer)
                                {
                                    if (cpt == 3)
                                    {
                                        score -= 1000;
                                    }
                                    else if (cpt == 2)
                                    {
                                        score -= 100;
                                    }
                                    else
                                    {
                                        score -= 10;
                                    }
                                }
                            }
                            else
                            {
                                if (this._beliefs.environment.Grid[i][j + cpt + 1].State != statePlayer || this._beliefs.environment.Grid[i][j - 1].State != statePlayer)
                                {
                                    if (cpt == 3)
                                    {
                                        score -= 1000;
                                    }
                                    else if (cpt == 2)
                                    {
                                        score -= 100;
                                    }
                                    else
                                    {
                                        score -= 10;
                                    }
                                }
                            }
                            cpt = 0;
                        }
                    }
                    //verif diagonale vers haut droite
                    if (i > 2 && j < 3)
                    {
                        if (this._beliefs.environment.Grid[i][j].State == statePlayer)
                        {
                            ++cpt;

                            while (this._beliefs.environment.Grid[i - cpt][j + cpt].State == statePlayer)
                            {
                                ++cpt;
                            }

                            if (i != 5 && j != 0)
                            {
                                if (this._beliefs.environment.Grid[i - cpt][j + cpt].State != stateOtherPlayer || this._beliefs.environment.Grid[i + 1][j - 1].State != stateOtherPlayer)
                                {
                                    if (cpt == 3)
                                    {
                                        score += 1000;
                                    }
                                    else if (cpt == 2)
                                    {
                                        score += 100;
                                    }
                                    else
                                    {
                                        score += 10;
                                    }
                                }
                            }
                            else
                            {
                                if (j + cpt + 1 < 7 && this._beliefs.environment.Grid[i - cpt][j + cpt].State != stateOtherPlayer)
                                {
                                    if (cpt == 3)
                                    {
                                        score += 1000;
                                    }
                                    else if (cpt == 2)
                                    {
                                        score += 100;
                                    }
                                    else
                                    {
                                        score += 10;
                                    }
                                }
                            }
                            cpt = 0;
                        }
                        else if (this._beliefs.environment.Grid[i][j].State == stateOtherPlayer)
                        {
                            ++cpt;

                            while (this._beliefs.environment.Grid[i - cpt][j + cpt].State == stateOtherPlayer)
                            {
                                ++cpt;
                            }

                            if (i != 5 && j != 0)
                            {
                                if (this._beliefs.environment.Grid[i - cpt][j + cpt].State != statePlayer || this._beliefs.environment.Grid[i + 1][j - 1].State != statePlayer)
                                {
                                    if (cpt == 3)
                                    {
                                        score -= 1000;
                                    }
                                    else if (cpt == 2)
                                    {
                                        score -= 100;
                                    }
                                    else
                                    {
                                        score -= 10;
                                    }
                                }
                            }
                            else
                            {
                                if (this._beliefs.environment.Grid[i - cpt][j + cpt].State != statePlayer)
                                {
                                    if (cpt == 3)
                                    {
                                        score -= 1000;
                                    }
                                    else if (cpt == 2)
                                    {
                                        score -= 100;
                                    }
                                    else
                                    {
                                        score -= 10;
                                    }
                                }
                            }
                            cpt = 0;
                        }
                    }

                    //verif diagonale vers haut gauche
                    if (i > 2 && j > 3)
                    {
                        if (this._beliefs.environment.Grid[i][j].State == statePlayer)
                        {
                            ++cpt;
                            while (this._beliefs.environment.Grid[i - cpt][j - cpt].State == statePlayer)
                            {
                                ++cpt;
                            }

                            if (j != 6 && i != 5)
                            {
                                if (this._beliefs.environment.Grid[i - cpt][j - cpt].State != stateOtherPlayer || this._beliefs.environment.Grid[i + 1][j + 1].State != stateOtherPlayer)
                                {
                                    if (cpt == 3)
                                    {
                                        score += 1000;
                                    }
                                    else if (cpt == 2)
                                    {
                                        score += 100;
                                    }
                                    else
                                    {
                                        score += 10;
                                    }
                                }
                            }
                            else
                            {
                                if (this._beliefs.environment.Grid[i - cpt][j - cpt].State != stateOtherPlayer)
                                {
                                    if (cpt == 3)
                                    {
                                        score += 1000;
                                    }
                                    else if (cpt == 2)
                                    {
                                        score += 100;
                                    }
                                    else
                                    {
                                        score += 10;
                                    }
                                }
                            }
                            cpt = 0;
                        }
                        else if (this._beliefs.environment.Grid[i][j].State == stateOtherPlayer)
                        {
                            ++cpt;

                            while (this._beliefs.environment.Grid[i - cpt][j - cpt].State == stateOtherPlayer)
                            {
                                ++cpt;
                            }

                            if (i != 5 && j != 6)
                            {
                                if (this._beliefs.environment.Grid[i - cpt][j - cpt].State != statePlayer || this._beliefs.environment.Grid[i + 1][j + 1].State != statePlayer)
                                {
                                    if (cpt == 3)
                                    {
                                        score -= 1000;
                                    }
                                    else if (cpt == 2)
                                    {
                                        score -= 100;
                                    }
                                    else
                                    {
                                        score -= 10;
                                    }
                                }
                            }
                            else
                            {
                                if (this._beliefs.environment.Grid[i - cpt][j - cpt].State != statePlayer)
                                {
                                    if (cpt == 3)
                                    {
                                        score -= 1000;
                                    }
                                    else if (cpt == 2)
                                    {
                                        score -= 100;
                                    }
                                    else
                                    {
                                        score -= 10;
                                    }
                                }
                            }
                            cpt = 0;
                        }
                    }
                }
            }
            return(score);
        }
Esempio n. 27
0
 private playerTurn getWinner(playerTurn playerToCheck)
 {
     return(this._environment.getWinner(playerToCheck));
 }