public static async Task<TicTacToeMove> MakeMinimaxAIMove( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, ILogger log) { var context = await FunctionContext<PlayFabIdRequest>.Create(req); Settings.TrySetSecretKey(context.ApiSettings); Settings.TrySetCloudName(context.ApiSettings); var playFabId = context.FunctionArgument.PlayFabId; // Attempt to load the Player's game state var state = await GameStateUtil.GetCurrentGameState(playFabId, context.ApiSettings, context.AuthenticationContext); // Look for a minimax AI move to make var aiMove = TicTacToeAI.GetNextMinimaxMove(state); // Store the AI move on the current game state var oneDimMoveIndex = aiMove.row * 3 + aiMove.col; state.Data[oneDimMoveIndex] = (int) OccupantType.AI; await GameStateUtil.UpdateCurrentGameState(state, playFabId, context.ApiSettings, context.AuthenticationContext); // Respond with the AI move return aiMove; }
public void FieldButtonClick(int position) { // return if position is already taken if (field[position] != 2) { return; } // make move MakeMove(player, position); // check end game CheckEndGame(); // return if game ended if (!gameActive) { return; } // make AI move MakeMove(ai, TicTacToeAI.AImakeMove(field, ai, GameControl.aiLevel)); // check end game CheckEndGame(); }
private void LoadGameInit() { // decide who plays first switch (GameControl.lastGameResult) { case "draw": player = GameControl.lastGamePlayer == 0 ? 1 : 0; break; case "win": player = 0; break; case "loose": player = 1; break; } ai = player == 0 ? 1 : 0; // if AI first, let him do a move if (ai == 0) { MakeMove(ai, TicTacToeAI.AImakeMove(field, ai, GameControl.aiLevel)); } // make texts show current data difficultyText.GetComponent <Text>().text = "Уровень ИИ: " + GameControl.GetAiLevelName(); winsText.GetComponent <Text>().text = "Победы: " + GameControl.wins.ToString(); loosesText.GetComponent <Text>().text = "Поражения: " + GameControl.looses.ToString(); drawsText.GetComponent <Text>().text = "Ничьи: " + GameControl.draws.ToString(); }
public TicTacToe() { InitializeComponent(); TicTacToeAI.StartScript(ButtonA1, ButtonA2, ButtonA3, ButtonB1, ButtonB2, ButtonB3, ButtonC1, ButtonC2, ButtonC3, DebuggerLabel, RecordLabel); SetSymbol(); }
public void RemovePlayer(string playerID) { game.RemovePlayer(playerID); if (IsSinglePlayer()) { game.RemovePlayer("AI"); AI = null; } }
/* * At the start of the game * Initialise player as X (id = 1) * Set game to easy mode (depth = 2) * Hide GameOver Panel * Calls setgamecontroller reference to apply gamecontroller functionality to each button */ void Start() { SetGameControllerReference(); GameOverPanel.SetActive(false); _playerId = 1; _gb = GameBoard.GetComponent <Gameboard>(); _ai = this.gameObject.GetComponent <TicTacToeAI>(); _ai.DepthCap = 2; }
void SetSymbol() { if (SymbolX.Checked) { TicTacToeAI.PlayerSymbol = eSymbol.X; } else { TicTacToeAI.PlayerSymbol = eSymbol.O; } TicTacToeAI.ChangeSetting(); }
void SetDifficulity() { if (Difficulity0.Checked) { TicTacToeAI.CompDifficulity = 0; } else if (Difficulity1.Checked) { TicTacToeAI.CompDifficulity = 1; } TicTacToeAI.ChangeSetting(); }
//开始游戏 public void StartGame(Game.TTT.PlayMode mode) { currentPlayMode = mode; view.StartPanel.gameObject.SetActive(false); view.GamePanel.gameObject.SetActive(true); if (mode == Game.TTT.PlayMode.OnePlayerMode) { aiTurn = !view.OffensiveToggle.isOn; if (aiTurn) { singlePlayerAI = new TicTacToeAI(Player.Player1); OnGameAreaClick(singlePlayerAI.NextStep(gameState)); } else { singlePlayerAI = new TicTacToeAI(Player.Player2); } } }
void SelectRegion(eRegion _region) { TicTacToeAI.Input(TicTacToeAI.PlayerSymbol, _region); }
private void Difficulity1_CheckedChanged(object sender, EventArgs e) { SetDifficulity(); TicTacToeAI.ChangeSetting(); }
private void ButtonPlayAgain_Click(object sender, EventArgs e) { TicTacToeAI.ResetBoard(); }
public void EnableAI() { AI = new TicTacToeAI(); game.AddPlayer("AI"); }
void Start() { _ai = Gb.gameObject.GetComponent <TicTacToeAI>(); _gc = Gb.gameObject.GetComponent <GameController>(); }