예제 #1
0
파일: RevGame.cs 프로젝트: cslecours/RevLib
        public IEnumerable<Coord> MakeListOfConvertedTokens(Player p, int x, int y)
        {
            var playChanges = new List<Coord>();

            OffsetCalculator calc = new OffsetCalculator(x, y);

            for (int dir = 0; dir < 9; dir++)
            {
                calc.setDirection(dir);
                int length = CountLine(p,calc);
                calc.MakeOffset(length);

                if (LineShouldChangeOwnership(length, calc, p))
                {
                    var lineChanges = ListChangesInLine(length, calc);
                    playChanges.AddRange(lineChanges);
                }
            }

            if(playChanges.Any())
            {
                playChanges.Add(new Coord(x, y));
            }

            return playChanges;
        }
예제 #2
0
 public void RemovePointFrom(Player p)
 {
     if (Scores.ContainsKey(p) && Scores[p].Score > 0)
     {
         Scores[p].Score--;
     }
 }
예제 #3
0
        public void Play(Player p, Coord start, Coord end)
        {
            if (CanSelectToPlay(p, start.x, start.y) && board.IsEmpty(end.x, end.y))
            {
                var distance = end - start;
                int travelLength = Math.Abs(distance.x) + Math.Abs(distance.y);

                //Move -> Remove original
                if (travelLength == 2)
                {
                    board[start.x, start.y] = null;
                }

                //Copy (or Move) -> Put token
                PutToken(p, end.x, end.y);
                var offsetCalc = new OffsetCalculator(end.x, end.y);
                for (int i = 0; i < 9; i++)
                {
                    offsetCalc.setDirection(i);
                    offsetCalc.MakeOffset(1);

                    if (board.CanOvertakeToken(p, offsetCalc.ResultX, offsetCalc.ResultY))
                    {
                        PutToken(p, offsetCalc.ResultX, offsetCalc.ResultY);
                    }
                }

                HandlePlayerChange();

                if (SnapshotContainer != null)
                {
                    SnapshotContainer.TakeSnapShot(new TwoPartTurn() { Start = start, End = end, PlayerThatPlayed = p, PlayerToPlay = CurrentPlayer, Board = board.Clone() });
                }
            }
        }
예제 #4
0
        public void TestPutTokenOnEmptySpace()
        {
            var board = new Board();
            Player b = new Player(Token.Black);
            Player w = new Player(Token.White);

            board[0, 0] = b;
            Assert.AreEqual(1, board.ScoreOf(b));
            Assert.AreEqual(0, board.ScoreOf(w));
        }
예제 #5
0
 public int ScoreOf(Player p)
 {
     if (Scores.ContainsKey(p))
     {
         return Scores[p].Score;
     }
     else
     {
         return 0;
     }
 }
예제 #6
0
 public void AddPointTo(Player p)
 {
     if (Scores.ContainsKey(p))
     {
         Scores[p].Score++;
     }
     else
     {
         Scores.Add(p, new PlayerScore() { Score = 1 });
     }
 }
예제 #7
0
파일: RevGame.cs 프로젝트: cslecours/RevLib
 public override bool CanPlay(Player p)
 {
     SpiralCoordEnumerator enumerator = new SpiralCoordEnumerator(8,1);
     while(enumerator.MoveNext())
     {
         var coord = enumerator.Current;
         if (CanPlayThere(p, coord.x, coord.y))
         {
             return true;
         }
     }
     return false;
 }
예제 #8
0
 public override bool CanPlay(Player p)
 {
     for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             if (CanSelectToPlay(p, i, j))
             {
                 return true;
             }
         }
     }
     return false;
 }
예제 #9
0
        public void TestCloneBoard()
        {
            var board = new Board();
            var player = new Player(Token.Black);
            board[0, 0] = player;

            var clonedBoard = board.Clone();
            Assert.AreEqual(player, clonedBoard[0, 0]);

            var white = new Player(Token.White);
            clonedBoard[4, 7] = white;

            Assert.AreNotEqual(board[4, 7], clonedBoard[4, 7]);
        }
예제 #10
0
 public bool CanPlayThere(Player p, Coord start, int x, int y)
 {
     if (board.IsInBoard(x,y) && board.IsEmpty(x,y))
     {
         Coord end = new Coord(x, y);
         var distance = end - start;
         int travelLength = Math.Abs(distance.x) + Math.Abs(distance.y);
         return travelLength == 1 || travelLength == 2;
     }
     else
     {
         return false;
     }
 }
예제 #11
0
        protected Dictionary<Coord, int> MakeListOfPossiblePlays(Player p, RevGame game)
        {
            int col = 8;
            int row = 8;
            Dictionary<Coord,int> d = new Dictionary<Coord, int>();

            for (int i = 0; i < col; i++)
            {
                for (int j = 0; j < row; j++)
                {
                    if (game.CanPlayThere(p, i, j))
                    {
                        var tokens = game.MakeListOfConvertedTokens(p, i, j);
                        d[new Coord(i,j)] = tokens.Count();
                    }
                }
            }
            return d;
        }
예제 #12
0
        public bool CanSelectToPlay(Player p, int x, int y)
        {
            var offcalc = new OffsetCalculator(x, y);

            if(board[x,y] == p){
                for (int i = 0; i < 9; i++)
                {
                    offcalc.setDirection(i);
                    for (int offset = 1; offset <= 2; offset++)
                    {
                        offcalc.MakeOffset(offset);
                        if (board.IsInBoard(offcalc.ResultX, offcalc.ResultY) && board.IsEmpty(offcalc.ResultX, offcalc.ResultY))
                        {
                            return true;
                        }
                    }
                }
            }
            return false;
        }
예제 #13
0
        public void TestIsEmpty()
        {
            Player p = new Player(Token.Black);

            Board board = new Board();
            Action<int, int, bool> test = (x, y, expected) =>
            {
                bool actual = board.IsEmpty(x, y);
                Assert.AreEqual(expected, actual);
            };

            test(0, 0, true);

            board[0, 0] = p;

            test(0, 0, false);

            board[0, 0] = null;

            test(0, 0, true);
        }
예제 #14
0
파일: RevGame.cs 프로젝트: cslecours/RevLib
        public bool CanPlayThere(Player p, int x, int y)
        {
            if (!IsValidPlay(p,x,y))
            {
                return false;
            }

            var calc = new OffsetCalculator(x, y);
            for (int dir = 0; dir < 9; dir++)
            {
                calc.setDirection(dir);
                int offset = CountLine(p,calc);

                if (offset > 1)
                {
                    return true;
                }
            }

            return false;
        }
예제 #15
0
 public abstract bool CanPlay(Player p);
예제 #16
0
 public int ScoreOf(Player p)
 {
     return board.ScoreOf(p);
 }
예제 #17
0
 private Player getNextPlayer(Player p)
 {
     return _players[(Array.IndexOf(_players, p) + 1) % _players.Length];
 }
예제 #18
0
 public void MakeCurrentTurnOf(Player p)
 {
     Current = p;
 }
예제 #19
0
 public bool IsPlayerInGame(Player p)
 {
     return _players.Contains(p);
 }
예제 #20
0
 public PlayerQueue(Player p1, Player p2)
 {
     _players = new Player[] { p1, p2 };
     Current = _players[0];
 }
예제 #21
0
파일: RevGame.cs 프로젝트: cslecours/RevLib
 private void PutTokens(Player p, IEnumerable<Coord> coords)
 {
     foreach (Coord item in coords)
     {
         PutToken(p, item.x, item.y);
     }
 }
예제 #22
0
        public void PutToken(Player p, int x, int y)
        {
            if (!IsValid(p,x,y))
            {
                throw new ArgumentException();
            }

            board[x, y] = p;
        }
예제 #23
0
 public bool IsValid(Player p, int x, int y)
 {
     return board.IsInBoard(x, y) && board[x,y] != p && playerQueue.IsPlayerInGame(p);
 }
예제 #24
0
파일: RevGame.cs 프로젝트: cslecours/RevLib
 public RevGame(Player black, Player white)
     : this(new PlayerQueue(black, white))
 {
 }
예제 #25
0
파일: RevGame.cs 프로젝트: cslecours/RevLib
 protected bool IsValidPlay(Player p, int x, int y)
 {
     return board.IsEmpty(x, y) && IsValid(p, x, y);
 }
예제 #26
0
파일: RevGame.cs 프로젝트: cslecours/RevLib
        private int CountLine(Player p, OffsetCalculator calc)
        {
            int offset = 0;

            do
            {
                offset++;
                calc.MakeOffset(offset);
            } while (board.CanOvertakeToken(p, calc.ResultX, calc.ResultY));

            if (!board.IsInBoard(calc.ResultX, calc.ResultY) || board[calc.ResultX, calc.ResultY] != p)
            {
                offset = 0;
            }

            return offset;
        }
예제 #27
0
 public void LoadBoard(Board b, Player p)
 {
     this.board = b;
     playerQueue.MakeCurrentTurnOf(p);
 }
예제 #28
0
파일: RevGame.cs 프로젝트: cslecours/RevLib
        public void Play(Player p, int x, int y)
        {
            if (!IsValidPlay(p, x, y))
            {
                return;
            }

            var list = MakeListOfConvertedTokens(p, x, y);
            if (list.Any())
            {
                PutTokens(p, list);
                HandlePlayerChange();
                if (SnapshotContainer != null)
                {
                    SnapshotContainer.TakeSnapShot(new OnePartTurn() { Coord = new Coord(x, y), PlayerThatPlayed = p, PlayerToPlay = CurrentPlayer, Board = board.Clone() });
                }
            }
        }
예제 #29
0
파일: RevTest.cs 프로젝트: cslecours/RevLib
        public void TestPutTokenWithNonValidPlayer()
        {
            var board = new RevGame();
            var player = new Player(0);

            board.PutToken(player, 5, 5);
        }
예제 #30
0
파일: RevGame.cs 프로젝트: cslecours/RevLib
 private bool LineShouldChangeOwnership(int length, OffsetCalculator calc, Player p)
 {
     return length > 0 && board[calc.ResultX, calc.ResultY] == p;
 }