Ejemplo n.º 1
0
 public bool Play(byte row, byte col)
 {
     if (!BoardUtil.CheckBounds(_size, row, col))
     {
         return(false);
     }
     if (_currentStatus.Board.Get(row, col) != WColor.EMPTY)
     {
         return(false);
     }
     else
     {
         BoardStatus temptNew = _currentStatus;
         if (!MoveUtils.Move(ref temptNew, row, col))
         {
             return(false);
         }
         if (!boardHistory.Contains(temptNew.ToString()))
         {
             boardHistory.Add(temptNew.ToString());
             _currentStatus = temptNew;
             _LatestMove    = new Tuple <byte, byte>(row, col);
             _numMoves++;
             return(true);
         }
         return(false);
     }
 }
Ejemplo n.º 2
0
 public static void RemoveStones(List <Tuple <byte, byte> > capturedStones, BoardStatus newStatus)
 {
     foreach (var stonePosition in capturedStones)
     {
         newStatus.Board[stonePosition.Item1, stonePosition.Item2] = WColor.EMPTY;
         newStatus.Board.ClearMark(stonePosition.Item1, stonePosition.Item2);
     }
 }
Ejemplo n.º 3
0
        public static bool CheckMove(BoardStatus status, byte row, byte col)
        {
            BoardStatus savedStatus = new BoardStatus(status);
            bool        ret         = Move(ref status, row, col);

            status = savedStatus;
            return(ret);
        }
Ejemplo n.º 4
0
 public void Reset()
 {
     boardHistory.Clear();
     _LatestMove     = null;
     _currentStatus  = new BoardStatus(_size);
     _currentRecMove = 0;
     boardHistory.Add(_currentStatus.ToString());
     _numMoves = 0;
 }
Ejemplo n.º 5
0
        public static bool CheckMove(BoardBase status, WColor turn, byte row, byte col)
        {
            BoardStatus toCheck = new BoardStatus(status.Size);

            toCheck.Board = new BoardBase(status);
            toCheck.Turn  = turn;
            bool ret = Move(ref toCheck, row, col);

            return(ret);
        }
Ejemplo n.º 6
0
 public AGame(byte size) : this()
 {
     _size               = size;
     _LatestMove         = null;
     _currentStatus      = new BoardStatus(_size);
     _currentStatus.Turn = WColor.BLACK;
     _numMoves           = 0;
     _currentRecMove     = 0;
     boardHistory.Add(_currentStatus.ToString());
 }
Ejemplo n.º 7
0
        private static List <Tuple <byte, byte> > Capture(BoardStatus newStatus, byte row, byte col, WColor color)
        {
            var       capturedStones = new List <Tuple <byte, byte> >();
            BoardBase bbTemp         = new BoardBase(newStatus.Board);

            if (!captureKernel(bbTemp, capturedStones, row, col, color))
            {
                capturedStones.Clear();
            }
            return(capturedStones);
        }
Ejemplo n.º 8
0
 public AGame(string fileName)
 {
     _gameRecord     = SGFParser.GetGameRecord(fileName);
     boardHistory    = new SortedSet <string>();
     _LatestMove     = null;
     _size           = _gameRecord.Size;
     _currentStatus  = new BoardStatus(_size);
     _numMoves       = 0;
     _currentRecMove = 0;
     boardHistory.Add(_currentStatus.ToString());
 }
Ejemplo n.º 9
0
 public AGame(Stream stream)
 {
     using (StreamReader reader = new StreamReader(stream))
     {
         string buffer = reader.ReadToEnd();
         _gameRecord = SGFParser.ParseGameRecord(buffer);
     }
     boardHistory    = new SortedSet <string>();
     _LatestMove     = null;
     _size           = _gameRecord.Size;
     _currentStatus  = new BoardStatus(_size);
     _numMoves       = 0;
     _currentRecMove = 0;
     boardHistory.Add(_currentStatus.ToString());
 }
Ejemplo n.º 10
0
        public static bool Move(ref BoardStatus status, byte row, byte col)
        {
            if (status.Board[row, col] != WColor.EMPTY)
            {
                return(false);
            }
            status.Board[row, col] = status.Turn;

            if (CalculateCaptureStones(row, col, status.Turn, ref status) == false)
            {
                status.Board[row, col] = WColor.EMPTY;
                return(false);
            }
            else
            {
                status.Turn = ColorUtils.Flip(status.Turn);
                return(true);
            }
        }
Ejemplo n.º 11
0
        private static bool CalculateCaptureStones(byte row, byte col, WColor color, ref BoardStatus newStatus)
        {
            List <Tuple <byte, byte> > capturedStones;
            bool captured = false;

            var flipColor = ColorUtils.Flip(color);

            if ((capturedStones = Capture(newStatus, (byte)(row + 1), col, flipColor)).Count > 0)
            {
                RemoveStones(capturedStones, newStatus);
                captured = true;
            }
            if ((capturedStones = Capture(newStatus, (byte)(row - 1), col, flipColor)).Count > 0)
            {
                RemoveStones(capturedStones, newStatus);
                captured = true;
            }
            if ((capturedStones = Capture(newStatus, row, (byte)(col + 1), flipColor)).Count > 0)
            {
                RemoveStones(capturedStones, newStatus);
                captured = true;
            }
            if ((capturedStones = Capture(newStatus, row, (byte)(col - 1), flipColor)).Count > 0)
            {
                RemoveStones(capturedStones, newStatus);
                captured = true;
            }

            if ((!captured) && ((capturedStones = Capture(newStatus, row, col, color)).Count > 0))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 12
0
        public static void PrintToConsole(BoardStatus boardStatus, Mask mask = null)
        {
            byte size = boardStatus.Board.Size;

            Console.WriteLine();
            ConsoleColor saveColor = Console.ForegroundColor;

            Console.Write("   ");
            Console.ForegroundColor = ConsoleColor.Gray;
            for (byte i = 0; i < size; i++)
            {
                Console.Write(' ');
                if (i < 8)
                {
                    Console.Write((char)(i + 'A'));
                }
                else
                {
                    Console.Write((char)(i + 'B'));
                }
            }
            Console.WriteLine();
            for (byte i = 0; i < size; i++)
            {
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.Write(" {0,2}", (int)(19 - i));
                for (byte j = 0; j < size; j++)
                {
                    WColor       stoneColor = boardStatus.Board.Get(j, i);
                    Mark         markColor  = boardStatus.Board.GetMark(j, i);
                    ConsoleColor fc         = ConsoleColor.Gray;
                    string       mark       = "";
                    if (stoneColor == WColor.EMPTY)
                    {
                        fc   = ConsoleColor.Gray;
                        mark = " .";
                    }
                    else if (stoneColor == WColor.WHITE)
                    {
                        fc   = ConsoleColor.Green;
                        mark = " X";
                    }
                    else if (stoneColor == WColor.BLACK)
                    {
                        fc   = ConsoleColor.Yellow;
                        mark = " O";
                    }

                    if (markColor == Mark.MARK1)
                    {
                        fc = ConsoleColor.Red;
                    }
                    if (mask.CheckMaskClose(j, i))
                    {
                        fc   = ConsoleColor.Gray;
                        mark = " #";
                    }
                    Console.ForegroundColor = fc;
                    Console.Write(mark);
                }
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.Write(" {0}", (int)(19 - i));
                Console.WriteLine();
            }
            Console.Write("   ");
            Console.ForegroundColor = ConsoleColor.Gray;
            for (byte i = 0; i < size; i++)
            {
                Console.Write(' ');
                if (i < 8)
                {
                    Console.Write((char)(i + 'A'));
                }
                else
                {
                    Console.Write((char)(i + 'B'));
                }
            }
            Console.WriteLine();
            Console.WriteLine();
            Console.ForegroundColor = saveColor;
        }
Ejemplo n.º 13
0
 public PartialBoard(BoardStatus status, Mask inputMask)
 {
     boardStatus = status;
     mask        = inputMask;
 }
Ejemplo n.º 14
0
 public BoardStatus(BoardStatus bs)
 {
     Board = new BoardBase(bs.Board);
     Turn  = bs.Turn;
 }