Exemple #1
0
        private Game(Game other)
            : this(other.RowCount, other.ColumnCount, other.WinningPaths, other.ValidMoves)
        {
            foreach (Cell cell in Cells())
            {
                this[cell] = other[cell];
            }

            _currentPlayerIndex = other._currentPlayerIndex;
        }
Exemple #2
0
        public void Play(Game game)
        {
            if (game.IsBoardFull)
            {
                throw new InvalidOperationException("Board is full");
            }

            GameDecisionNode decision = new GameDecisionNode(game);
            decision.BuildTree(maxDepth: 3);

            var move = decision.Children.OrderByDescending(c => c.CalculateValue(game.CurrentPlayer)).FirstOrDefault();
            if (move != null)
            {
                //var value = move.Value;
                //move = decision.Children.Where(v => v.Value == value).Random();

                game.Play(move.Cell);
            }
            else
            {
                PickRandomMove(game);
            }
        }
Exemple #3
0
 private void PickRandomMove(Game game)
 {
     var rnd = new Random();
     var cell = game.Cells().Where(c => game[c] == BlockState.Empty).Random();
     game.Play(cell);
 }
Exemple #4
0
 public IGame PlayInCopy(Cell cell)
 {
     Game result = new Game(this);
     result.Play(cell);
     return result;
 }
Exemple #5
0
 public virtual void Start(Game game)
 {
     if (OwnedGames.Contains(game))
     {
         game.Start();
     }
 }
Exemple #6
0
 public virtual void Join(Game game)
 {
     game.AddPlayer(this);
 }
Exemple #7
0
 public virtual Game CreateGame(string gameName)
 {
     var game = new Game(gameName, this);
     OwnedGames.Add(game);
     return game;
 }