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

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