public void checkWinner() { int player1 = MiniMaxScript.numOfConnect(gameGrid, 1, 4); int player2 = MiniMaxScript.numOfConnect(gameGrid, 2, 4); if (player1 != 0 || player2 != 0) { if (player1 != 0) { gameControl.endGame(1); } else { gameControl.endGame(2); } } if (BoardUtility.boardFull(gameGrid)) { gameControl.endGame(0); } }
// Update is called once per frame void Update() { if (gameControl.gamestate == "gameplay") { countdown += Time.deltaTime; //player move //only usable when player is allowed to move if ((player1 == InputChoice.Player && redTurn) || (player2 == InputChoice.Player && !redTurn)) { for (int i = 1; i < 8; i++) { if (Input.GetKeyDown(i.ToString())) { buttonPressed(i - 1); } } for (int i = 0; i < 7; i++) { if (allowRemove) { if (Input.GetKeyDown(removeCode[i])) { removeButtonPressed(i); } } else { break; } } } //if the first player is also a computer but with only random move if ((player1 == InputChoice.Random && redTurn) || (player2 == InputChoice.Random && !redTurn)) { if (countdown >= computerThinkTime) { int move = MiniMaxScript.randomMove(gameGrid, 1, allowRemove); if (move < 7) { spawnChess(move); } else { removeChess(BoardUtility.getIndexOfRemove(gameGrid, move, 1)); } } } //if vsComputer if ((player1 == InputChoice.HeuristicOne && redTurn) || (player2 == InputChoice.HeuristicOne && !redTurn) || (player1 == InputChoice.HeuristicTwo && redTurn) || (player2 == InputChoice.HeuristicTwo && !redTurn)) { int heuristic; int player; //check which is current player and using which heuristic if (player1 == InputChoice.HeuristicOne && redTurn) { heuristic = 1; player = 1; } else if (player1 == InputChoice.HeuristicOne && !redTurn) { heuristic = 1; player = 2; } else if (player1 == InputChoice.HeuristicTwo && redTurn) { heuristic = 2; player = 1; } else { heuristic = 2; player = 2; } if (countdown >= computerThinkTime) { //set minimax to also allow remove if (allowRemove) { //gameGrid, depth, playerKey, heristic int num = MiniMaxScript.miniMaxResultWithRemove(gameGrid, depth, player, heuristic); if (num < 7) { spawnChess(num); } else { removeChess(num - 7); } } else { spawnChess(MiniMaxScript.miniMaxResult(gameGrid, depth, player, heuristic)); } } } } }