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; } } } }
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; }