3 * @purpose Class that represents an agent which will play qchess
6 import java.util.Random;
7 import java.util.Vector;
11 public Agent(String colour) throws Exception
13 this.colour = Piece.str2colour(colour);
15 this.board = new Board();
17 this.rand = new Random();
20 public static void main(String [] args)
22 String colour = Reader.readLine();
26 Agent agent = new Agent(colour);
31 //System.err.println("EXCEPTION: agent.Run - "+e);
36 public void Run() throws Exception
40 Vector<String> v = Reader.readTokens();
42 String cmd = v.get(0);
44 if (cmd.compareTo("QUIT") == 0)
46 else if (cmd.compareTo("SELECTION?") == 0)
49 System.out.println(Integer.toString(s.x) + " " + Integer.toString(s.y));
51 else if (cmd.compareTo("MOVE?") == 0)
54 System.out.println(Integer.toString(s.x) + " " + Integer.toString(s.y));
58 int x = Integer.parseInt(v.get(0));
59 int y = Integer.parseInt(v.get(1));
60 if (v.get(2).compareTo("->") == 0)
62 int x2 = Integer.parseInt(v.get(3));
63 int y2 = Integer.parseInt(v.get(4));
64 board.Update_move(x, y, x2, y2);
68 int index = Integer.parseInt(v.get(2));
69 String type = v.get(3);
70 board.Update_select(x, y, index, type);
76 public Square select() throws Exception
78 Vector<Piece> p = board.pieces(colour);
79 int choice = rand.nextInt(p.size());
80 Square s = board.Get_square(p.get(choice).x, p.get(choice).y);
82 throw new Exception("ARGH");
89 Vector<Square> v = new Vector<Square>();
90 board.Get_moves(selected, v);
91 return v.get(rand.nextInt(v.size()));
94 private final Piece.Colour colour; // colour of the agent; do not change it
96 private Piece selected;