Example #1
0
        static void Main(string[] args)
        {
            Board board = new Board(19);
            Parser parser = new Parser();
            BoardPosition pos;

/*            System.IO.TextReader sr = System.IO.File.OpenText("game.sgf");
            string zeile;
            while(sr.Peek() != -1)
            {
                zeile = sr.ReadLine();
                BoardPosition p = parser.ParseString(zeile);
                if (p != null)
                {
                    Console.WriteLine("Setting stone at " + p.x + "x" + p.y);
                    board.SetStone(p);
                }
            }*/

            board.PrintToConsole();
            while ((pos = parser.ParseString(Console.ReadLine())) != null)
            {
                board.SetStone(pos);
                System.Console.Clear();
                board.PrintToConsole();
                
                Random rand = new Random();
                int x = rand.Next(20);
                int y = rand.Next(20);
                BoardPosition comp = new BoardPosition(x, y, BoardPositionEntry.WHITE);
                board.SetStone(comp);
            }
        }
Example #2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="g"></param>
 public void JoinWithGroup(Board board, Group g)
 {
     foreach (BoardPosition pos in g.Stones)
     {
         Stones.AddLast(pos);
         pos.Group = this;
     }
     board.Groups.Remove(g);
 }
Example #3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="pos"></param>
 /// <returns></returns>
 public bool ConnectsWithGroup(Board board, BoardPosition pos)
 {
     foreach(BoardPosition stone in Stones)
     {
         if (board.DirectNeighbors(pos, stone) && pos.Contains == stone.Contains)
         {
             if(pos.Group != this)
                 return true;
         }
     }
     return false;
 }
Example #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="board"></param>
        /// <returns></returns>
        public int GetFreeLiberties(Board board)
        {
            bool[,] marked = new bool[board.Size, board.Size];

            int liberties = 0;

            foreach (BoardPosition pos in Stones)
            {
                if (board.North(pos) != null)
                {
                    if (board.North(pos).Contains == BoardPositionEntry.EMTPY)
                    {
                        if (!marked[board.North(pos).x, board.North(pos).y])
                        {
                            liberties++;
                            marked[board.North(pos).x, board.North(pos).y] = true;
                        }
                    }
                }
                if (board.East(pos) != null)
                {
                    if (board.East(pos).Contains == BoardPositionEntry.EMTPY)
                    {
                        if (!marked[board.East(pos).x, board.East(pos).y])
                        {
                            liberties++;
                            marked[board.East(pos).x, board.East(pos).y] = true;
                        }
                    }
                }
                if (board.South(pos) != null)
                {
                    if (board.South(pos).Contains == BoardPositionEntry.EMTPY)
                    {
                        if (!marked[board.South(pos).x, board.South(pos).y])
                        {
                            liberties++;
                            marked[board.South(pos).x, board.South(pos).y] = true;
                        }
                    }
                }
                if (board.West(pos) != null)
                {
                    if (board.West(pos).Contains == BoardPositionEntry.EMTPY)
                    {
                        if (!marked[board.West(pos).x, board.West(pos).y])
                        {
                            liberties++;
                            marked[board.West(pos).x, board.West(pos).y] = true;
                        }
                    }
                }
            }
            return liberties;
        }
Example #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public int RemoveGroup(Board board)
        {
            int size = Stones.Count;
            BoardPositionEntry entry = BoardPositionEntry.EMTPY;

            foreach (BoardPosition pos in Stones)
            {
                entry = pos.Contains;
                board.RemoveStone(pos);
            }
            Stones.Clear();
            board.Groups.Remove(this);

            return size;
        }