private static void DrawSpace(TicTacToeEnvironment environment, ITicTacToeBoardSpace space, Graphics g, Pen pen) { int x = space.ColumnIndex * CellSize; int y = space.RowIndex * CellSize; if (environment.State == EnvironmentState.Finished) { var winnerSpaces = environment.GetWinnerSpaces(); if (winnerSpaces.Contains(space)) { var brush = Brushes.Red; g.FillRectangle(brush, space.ColumnIndex * CellSize, space.RowIndex * CellSize, CellSize, CellSize); } } switch (space.SpaceType) { case SpaceType.Cross: g.DrawImage(environment.CrossBot.UIInformation.Avatar, x, y, CellSize, CellSize); break; case SpaceType.Nought: g.DrawImage(environment.NoughtBot.UIInformation.Avatar, x, y, CellSize, CellSize); break; } g.DrawRectangle(pen, x, y, CellSize, CellSize); }
public TicTacToeAction GetAction(TicTacToeEnvironment environment) { var action = _isFirstAction ? _rng.Choice(environment.ActionSpace()) : _innerAgent.GetAction(environment); _isFirstAction = false; return(action); }
public void FirstActionIsRandom() { var environment = new TicTacToeEnvironment(new FirstAvailableSlotPlayer(BoardTile.O)); var innerPolicy = new MonteCarloTicTacToeAgent(BoardTile.X); var distinctFirstActions = Enumerable.Range(0, 10) .Select(_ => new ExploringStartPolicy(innerPolicy).GetAction(environment)) .Distinct(); Assert.Greater(distinctFirstActions.Count(), 1); }
public void Setup() { _opponent = Substitute.For <ITicTacToePlayer>(); _opponent.Tile.Returns(BoardTile.O); _opponent.GetAction(Arg.Any <Board>()) .Returns(new TicTacToeAction { Position = 0, Tile = BoardTile.O }); _env = new TicTacToeEnvironment(_opponent); }
public TicTacToeAction GetAction(TicTacToeEnvironment environment) => _ticTacToePlayer.GetAction(environment.CurrentState);