Ejemplo n.º 1
0
        public ButtonViewModel(int row,int col,Game game)
        {
            this.game = game;
            pos = new Vector2D(row-1,col-1);

            Owner = game.Board[pos].Owner;

            IsValidMove = game.Board[pos].IsValidMove;

            Square = game.Board[pos];

            click=new ClickCommand(this);
        }
Ejemplo n.º 2
0
 private int Weight( IGrid<Player> board, Vector2D p )
 {
     if ( board.InCorner( p ) )
     {
         return cornerWeight;
     }
     else if ( board.OnRim( p ) )
     {
         return rimWeight;
     }
     else
     {
         return 1;
     }
 }
Ejemplo n.º 3
0
 public bool IsValidMove( Vector2D position )
 {
     return state.Value.IsValidMove( position );
 }
Ejemplo n.º 4
0
        public int? FindDistanceToCaptureTwin( Vector2D position, Vector2D direction, Player player )
        {
            var slice = grid.Slice( position, direction );

            for ( var i = 1; i < slice.End; ++i )
            {
                if ( slice[i].Value == null )
                {
                    return null;
                }
                else if ( slice[i].Value == player )
                {
                    return i;
                }
            }

            return null;
        }
Ejemplo n.º 5
0
 public Square( Game game, Vector2D position )
 {
     this.game = game;
     this.position = position;
     this.owner = Cell.Derived( () => game.GetOwnerAt( position ) );
     this.isValidMove = Cell.Derived( () => game.IsValidMove( position ) );
 }
Ejemplo n.º 6
0
 public abstract bool IsValidMove( Vector2D position );
Ejemplo n.º 7
0
 public IEnumerable<Vector2D> Captured( Vector2D position )
 {
     return state.Value.Captured( position );
 }
Ejemplo n.º 8
0
 public void PlaceStone( Vector2D position, Player player )
 {
     if ( !IsValidMove( position, player ) )
     {
         throw new ArgumentException( string.Format( "{0} cannot place stone on position {1}", player.ToString(), position.ToString() ) );
     }
     else
     {
         this.grid[position].Value = player;
         CaptureStones( position, player );
     }
 }
Ejemplo n.º 9
0
            public override void MakeMove( Vector2D position )
            {
                if ( !IsValidMove( position ) )
                {
                    throw new ArgumentException( "Not a valid move" );
                }
                else
                {
                    board.PlaceStone( position, currentPlayer );

                    if ( board.HasValidMove( currentPlayer.Other ) )
                    {
                        currentPlayer = currentPlayer.Other;
                    }
                    else if ( !board.HasValidMove( currentPlayer ) )
                    {
                        state.Value = new GameOver( state, board );
                    }
                }
            }
Ejemplo n.º 10
0
 public int ManhattanDistanceTo( Vector2D v )
 {
     if ( v == null )
     {
         throw new ArgumentNullException( "v" );
     }
     else
     {
         return Math.Abs( X - v.X ) + Math.Abs( Y - v.Y );
     }
 }
Ejemplo n.º 11
0
 public override bool IsValidMove( Vector2D position )
 {
     return false;
 }
Ejemplo n.º 12
0
 public Player this[Vector2D position]
 {
     get
     {
         return this.grid[position].Value;
     }
 }
Ejemplo n.º 13
0
 public bool Equals( Vector2D v )
 {
     return !object.ReferenceEquals( v, null ) && this.x == v.x && this.y == v.y;
 }
Ejemplo n.º 14
0
 private void CaptureStones( Vector2D position, Player player )
 {
     foreach ( var p in CapturedStones( position, player ) )
     {
         grid[p].Value = player;
     }
 }
Ejemplo n.º 15
0
        private IEnumerable<Vector2D> CapturedStones( Vector2D position, Vector2D direction, Player player )
        {
            var distanceToTwin = FindDistanceToCaptureTwin( position, direction, player );

            if ( distanceToTwin.HasValue )
            {
                for ( var i = 1; i != distanceToTwin; ++i )
                {
                    var p = position + i * direction;

                    yield return p;
                }
            }
        }
Ejemplo n.º 16
0
 private static Player StoneAtPositionInDefaultInitialGrid( Vector2D position )
 {
     if ( position == new Vector2D( 3, 4 ) || position == new Vector2D( 4, 3 ) )
     {
         return Player.ONE;
     }
     else if ( position == new Vector2D( 3, 3 ) || position == new Vector2D( 4, 4 ) )
     {
         return Player.TWO;
     }
     else
     {
         return null;
     }
 }
Ejemplo n.º 17
0
 public void MakeMove( Vector2D position )
 {
     state.Value.MakeMove( position );
 }
Ejemplo n.º 18
0
 public override IEnumerable<Vector2D> Captured( Vector2D position )
 {
     if ( IsValidMove( position ) )
     {
         return board.CapturedStones( position, currentPlayer );
     }
     else
     {
         return Enumerable.Empty<Vector2D>();
     }
 }
Ejemplo n.º 19
0
 public override IEnumerable<Vector2D> Captured( Vector2D position )
 {
     throw new InvalidOperationException();
 }
Ejemplo n.º 20
0
        public bool IsValidMove( Vector2D position, Player player )
        {
            if ( position == null )
            {
                throw new ArgumentNullException( "position" );
            }
            else if ( player == null )
            {
                throw new ArgumentNullException( "player" );
            }
            else if ( grid[position].Value == null )
            {
                foreach ( var direction in Vector2D.Directions )
                {
                    var distance = FindDistanceToCaptureTwin( position, direction, player );

                    if ( distance.HasValue && distance.Value > 1 )
                    {
                        return true;
                    }
                }

                return false;
            }
            else
            {
                return false;
            }
        }
Ejemplo n.º 21
0
 public override void MakeMove( Vector2D position )
 {
     throw new InvalidOperationException( "Game is over, cannot make moves" );
 }
Ejemplo n.º 22
0
 public override void MakeMove( Vector2D position )
 {
     throw new InvalidOperationException();
 }
Ejemplo n.º 23
0
 public override bool IsValidMove( Vector2D position )
 {
     return board.IsValidMove( position, this.currentPlayer );
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Computes which positions would be captured if the current player
 /// were to put his next stone at the specified position.
 /// </summary>
 /// <param name="position">Position at which the current player intends to put his stone.</param>
 /// <returns>A sequence of all stones that would be captured by the specified move.</returns>
 private IEnumerable<Vector2D> CapturedBy( Vector2D position )
 {
     return gameState.Captured( position );
 }
Ejemplo n.º 25
0
 public abstract IEnumerable<Vector2D> Captured( Vector2D position );
Ejemplo n.º 26
0
 private Player GetOwnerAt( Vector2D position )
 {
     return gameState.Board[position];
 }
Ejemplo n.º 27
0
 public abstract void MakeMove( Vector2D position );
Ejemplo n.º 28
0
 private bool IsValidMove( Vector2D position )
 {
     return gameState.IsValidMove( position );
 }
Ejemplo n.º 29
0
        private void PlaceStone( Vector2D position )
        {
            gameState.MakeMove( position );

            Refresh();
        }
Ejemplo n.º 30
0
 public IEnumerable<Vector2D> CapturedStones( Vector2D position, Player player )
 {
     foreach ( var direction in Vector2D.Directions )
     {
         foreach ( var p in CapturedStones( position, direction, player ) )
         {
             yield return p;
         }
     }
 }