Example #1
0
File: Game.cs Project: ngeor/games
        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;
        }
Example #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);
            }
        }
Example #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);
 }
Example #4
0
File: Game.cs Project: ngeor/games
 public IGame PlayInCopy(Cell cell)
 {
     Game result = new Game(this);
     result.Play(cell);
     return result;
 }
Example #5
0
 public virtual void Start(Game game)
 {
     if (OwnedGames.Contains(game))
     {
         game.Start();
     }
 }
Example #6
0
 public virtual void Join(Game game)
 {
     game.AddPlayer(this);
 }
Example #7
0
 public virtual Game CreateGame(string gameName)
 {
     var game = new Game(gameName, this);
     OwnedGames.Add(game);
     return game;
 }