Example #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);
        }
Example #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;
     }
 }
Example #3
0
 public bool IsValidMove( Vector2D position )
 {
     return state.Value.IsValidMove( position );
 }
Example #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;
        }
Example #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 ) );
 }
Example #6
0
 public abstract bool IsValidMove( Vector2D position );
Example #7
0
 public IEnumerable<Vector2D> Captured( Vector2D position )
 {
     return state.Value.Captured( position );
 }
Example #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 );
     }
 }
Example #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 );
                    }
                }
            }
Example #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 );
     }
 }
Example #11
0
 public override bool IsValidMove( Vector2D position )
 {
     return false;
 }
Example #12
0
 public Player this[Vector2D position]
 {
     get
     {
         return this.grid[position].Value;
     }
 }
Example #13
0
 public bool Equals( Vector2D v )
 {
     return !object.ReferenceEquals( v, null ) && this.x == v.x && this.y == v.y;
 }
Example #14
0
 private void CaptureStones( Vector2D position, Player player )
 {
     foreach ( var p in CapturedStones( position, player ) )
     {
         grid[p].Value = player;
     }
 }
Example #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;
                }
            }
        }
Example #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;
     }
 }
Example #17
0
 public void MakeMove( Vector2D position )
 {
     state.Value.MakeMove( position );
 }
Example #18
0
 public override IEnumerable<Vector2D> Captured( Vector2D position )
 {
     if ( IsValidMove( position ) )
     {
         return board.CapturedStones( position, currentPlayer );
     }
     else
     {
         return Enumerable.Empty<Vector2D>();
     }
 }
Example #19
0
 public override IEnumerable<Vector2D> Captured( Vector2D position )
 {
     throw new InvalidOperationException();
 }
Example #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;
            }
        }
Example #21
0
 public override void MakeMove( Vector2D position )
 {
     throw new InvalidOperationException( "Game is over, cannot make moves" );
 }
Example #22
0
 public override void MakeMove( Vector2D position )
 {
     throw new InvalidOperationException();
 }
Example #23
0
 public override bool IsValidMove( Vector2D position )
 {
     return board.IsValidMove( position, this.currentPlayer );
 }
Example #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 );
 }
Example #25
0
 public abstract IEnumerable<Vector2D> Captured( Vector2D position );
Example #26
0
 private Player GetOwnerAt( Vector2D position )
 {
     return gameState.Board[position];
 }
Example #27
0
 public abstract void MakeMove( Vector2D position );
Example #28
0
 private bool IsValidMove( Vector2D position )
 {
     return gameState.IsValidMove( position );
 }
Example #29
0
        private void PlaceStone( Vector2D position )
        {
            gameState.MakeMove( position );

            Refresh();
        }
Example #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;
         }
     }
 }