Esempio n. 1
0
        public List<Point> nextMovePlayOut(Board board)
        {
            PlayResult p = new PlayResult(board);
            Attack a = new Attack(board);

            int t = board.turn;
            PointSet ps;
            for(int i=2;i>0;--i)
            {
                ps = board.stones[1 - t] & a.attack[t, i];
                if (ps.size() != 0)
                {
                    List<Point> l = ps.toList();
                    PointSet res = new PointSet();
                    foreach (Point n in l)
                    {
                        res = res | PointSet.around[n.x, n.y];
                    }
                    res = res & p.valid;
                    if (res.size() != 0)
                    {
                        return res.toList();
                    }
                }
            }
            ps = a.attack[0, 0] & a.attack[1, 0];
            ps = ps & p.valid;
            if (ps.size() != 0)
            {
                return ps.toList();
            }
            return p.valid.toList();
        }
Esempio n. 2
0
        public PlayResult(Board board)
        {
            valid = new PointSet();
            invalid = new PointSet();
            Point p = new Point();

            for(int x=0;x<Info.N;++x)
            {
                for (int y = 0; y < Info.N; ++y)
                {
                    p.x = x;
                    p.y = y;
                    Info.GameState s = board.test_play(p);
                    switch(s)
                    {
                        case Info.GameState.VALID_MOVE:
                            valid.set(p);
                            break;
                        case Info.GameState.INVALID_MOVE:
                            invalid.set(p);
                            break;
                        default:
                            break;
                    }
                }
            }
        }
Esempio n. 3
0
 public static PointSet operator |(PointSet a, PointSet b)
 {
     PointSet res = new PointSet();
     res.table[0] = a.table[0] | b.table[0];
     res.table[1] = a.table[1] | b.table[1];
     return res;
 }
Esempio n. 4
0
        public Attack(Board board)
        {
            attack = new PointSet[2, 3];
            for (int i = 0; i < 2; ++i)
            {
                for (int j = 0; j < 3; ++j)
                {
                    attack[i, j] = new PointSet();
                }
            }

            for (int x = 0; x < Info.N; ++x)
            {
                for (int y = 0; y < Info.N; ++y)
                {
                    Point p = new Point(x, y);
                    PointSet ps = PointSet.around[x, y] & board.stones[0];
                    int s = ps.size();
                    if (s<=2)
                    {
                        attack[0,s].set(p);
                    }

                    ps = PointSet.around[x, y] & board.stones[1];
                    s = ps.size();
                    if (s <= 2)
                    {
                        attack[1, s].set(p);
                    }
                }
            }
        }
Esempio n. 5
0
 public static PointSet operator -(PointSet a, PointSet b)
 {
     PointSet res = new PointSet();
     res.table[0] = a.table[0] & (~b.table[0]);
     res.table[1] = a.table[1] & (~b.table[1]);
     return res;
 }
Esempio n. 6
0
 public Board(Board b)
 {
     points = new List<Point>(b.points);
     stones = new PointSet[2];
     stones[0] = new PointSet(b.stones[0]);
     stones[1] = new PointSet(b.stones[1]);
     turn = b.turn;
 }
Esempio n. 7
0
 public Board()
 {
     points = new List<Point>();
     stones = new PointSet[2];
     stones[0] = new PointSet();
     stones[1] = new PointSet();
     turn = 0;
 }
Esempio n. 8
0
 public PointSet(PointSet p)
 {
     table = new long[] { p.table[0], p.table[1] };
 }
Esempio n. 9
0
        public Info.GameState play(Point p)
        {
            if (p == Point.Pass)
            {
                if (points.Count > 0)
                {
                    if (points.Last() == Point.Pass)
                    {
                        points.Add(p);
                        return Info.GameState.END_GAME;
                    }
                }
                points.Add(p);
                turn = 1 - turn;
                return Info.GameState.VALID_MOVE;
            }
            if (p.x < 0 || p.x >= Info.N || p.y < 0 || p.y >= Info.N)
            {
                return Info.GameState.INVALID_MOVE;
            }
            if (get(p) != Info.Stones.EMPTY)
            {
                return Info.GameState.INVALID_MOVE;
            }

            if ((PointSet.around[p.x, p.y] & stones[opponent()]).size() >= 3)
            {
                return Info.GameState.INVALID_MOVE;
            }

            points.Add(p);
            stones[turn].set(p);

            List<Point> list = PointSet.around[p.x, p.y].toList();
            PointSet kill = new PointSet();
            foreach (Point i in list)
            {
                if ((PointSet.around[i.x, i.y] & stones[turn]).size() >= 3)
                {
                    kill.set(i);
                }
            }
            stones[opponent()] = stones[opponent()] - kill;
            turn = 1 - turn;
            return Info.GameState.VALID_MOVE;
        }