コード例 #1
0
ファイル: ViewModel.cs プロジェクト: PieterHuybrechts/Reversi
        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
ファイル: IReversiHeuristic.cs プロジェクト: Bawaw/Reversi
 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
ファイル: GameState.cs プロジェクト: Bawaw/Reversi
 public bool IsValidMove( Vector2D position )
 {
     return state.Value.IsValidMove( position );
 }
コード例 #4
0
ファイル: GameBoard.cs プロジェクト: Bawaw/Reversi
        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
ファイル: Game.cs プロジェクト: PieterHuybrechts/Reversi
 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
ファイル: GameState.cs プロジェクト: Bawaw/Reversi
 public abstract bool IsValidMove( Vector2D position );
コード例 #7
0
ファイル: GameState.cs プロジェクト: Bawaw/Reversi
 public IEnumerable<Vector2D> Captured( Vector2D position )
 {
     return state.Value.Captured( position );
 }
コード例 #8
0
ファイル: GameBoard.cs プロジェクト: Bawaw/Reversi
 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
ファイル: GameState.cs プロジェクト: Bawaw/Reversi
            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
ファイル: GameState.cs プロジェクト: Bawaw/Reversi
 public override bool IsValidMove( Vector2D position )
 {
     return false;
 }
コード例 #12
0
ファイル: GameBoard.cs プロジェクト: Bawaw/Reversi
 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
ファイル: GameBoard.cs プロジェクト: Bawaw/Reversi
 private void CaptureStones( Vector2D position, Player player )
 {
     foreach ( var p in CapturedStones( position, player ) )
     {
         grid[p].Value = player;
     }
 }
コード例 #15
0
ファイル: GameBoard.cs プロジェクト: Bawaw/Reversi
        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
ファイル: GameBoard.cs プロジェクト: Bawaw/Reversi
 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
ファイル: GameState.cs プロジェクト: Bawaw/Reversi
 public void MakeMove( Vector2D position )
 {
     state.Value.MakeMove( position );
 }
コード例 #18
0
ファイル: GameState.cs プロジェクト: Bawaw/Reversi
 public override IEnumerable<Vector2D> Captured( Vector2D position )
 {
     if ( IsValidMove( position ) )
     {
         return board.CapturedStones( position, currentPlayer );
     }
     else
     {
         return Enumerable.Empty<Vector2D>();
     }
 }
コード例 #19
0
ファイル: GameState.cs プロジェクト: Bawaw/Reversi
 public override IEnumerable<Vector2D> Captured( Vector2D position )
 {
     throw new InvalidOperationException();
 }
コード例 #20
0
ファイル: GameBoard.cs プロジェクト: Bawaw/Reversi
        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
ファイル: GameState.cs プロジェクト: Bawaw/Reversi
 public override void MakeMove( Vector2D position )
 {
     throw new InvalidOperationException( "Game is over, cannot make moves" );
 }
コード例 #22
0
ファイル: GameState.cs プロジェクト: PieterHuybrechts/Reversi
 public override void MakeMove( Vector2D position )
 {
     throw new InvalidOperationException();
 }
コード例 #23
0
ファイル: GameState.cs プロジェクト: Bawaw/Reversi
 public override bool IsValidMove( Vector2D position )
 {
     return board.IsValidMove( position, this.currentPlayer );
 }
コード例 #24
0
ファイル: Game.cs プロジェクト: PieterHuybrechts/Reversi
 /// <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
ファイル: GameState.cs プロジェクト: Bawaw/Reversi
 public abstract IEnumerable<Vector2D> Captured( Vector2D position );
コード例 #26
0
ファイル: Game.cs プロジェクト: PieterHuybrechts/Reversi
 private Player GetOwnerAt( Vector2D position )
 {
     return gameState.Board[position];
 }
コード例 #27
0
ファイル: GameState.cs プロジェクト: Bawaw/Reversi
 public abstract void MakeMove( Vector2D position );
コード例 #28
0
ファイル: Game.cs プロジェクト: PieterHuybrechts/Reversi
 private bool IsValidMove( Vector2D position )
 {
     return gameState.IsValidMove( position );
 }
コード例 #29
0
ファイル: Game.cs プロジェクト: PieterHuybrechts/Reversi
        private void PlaceStone( Vector2D position )
        {
            gameState.MakeMove( position );

            Refresh();
        }
コード例 #30
0
ファイル: GameBoard.cs プロジェクト: Bawaw/Reversi
 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;
         }
     }
 }