Final Commit
[progcomp2013.git] / agents / java / Piece.java
1 /**
2  * @file Piece.java
3  * @purpose Represent Quantum Chess Piece
4  * @author Sam Moore (matches@ucc.asn.au)
5  */
6
7
8
9 /**
10  * @class Piece
11  * @purpose Represent a quantum chess piece
12  */
13 public class Piece
14 {
15                 public enum Type {PAWN, BISHOP, KNIGHT, ROOK, QUEEN, KING, UNKNOWN};
16                 public enum Colour {WHITE, BLACK};
17
18                 public Piece(int new_x, int new_y, Colour new_colour, Type type1, Type type2)
19                 {
20                         this.x = new_x;
21                         this.y = new_y;
22                         this.colour = new_colour;
23                         this.types = new Piece.Type[2];
24                         this.types[0] = type1;
25                         this.types[1] = type2;
26                         this.type_index = -1;
27                 }
28
29                 public Piece(Piece cpy)
30                 {
31                         this.x = cpy.x;
32                         this.y = cpy.y;
33                         this.colour = cpy.colour;
34                         this.types[0] = cpy.types[0];
35                         this.types[1] = cpy.types[1];
36                         this.type_index = cpy.type_index;
37                 }
38
39                 public int x; 
40                 public int y; // position of the piece
41                 public Piece.Colour colour; // colour of the piece
42                 public int type_index; // indicates state the piece is in; 0, 1, or -1 (unknown)
43                 public Piece.Type[] types; // states of the piece
44                 public Piece.Type current_type; // current state of the piece
45                 
46                 public static Piece.Type str2type(String str) throws Exception
47                 {
48                         if (str.compareTo("king") == 0)
49                                 return Piece.Type.KING;
50                         else if (str.compareTo("queen") == 0)
51                                 return Piece.Type.QUEEN;
52                         else if (str.compareTo("rook") == 0)
53                                 return Piece.Type.ROOK;
54                         else if (str.compareTo("bishop") == 0)
55                                 return Piece.Type.BISHOP;
56                         else if (str.compareTo("knight") == 0)
57                                 return Piece.Type.KNIGHT;
58                         else if (str.compareTo("pawn") == 0)
59                                 return Piece.Type.PAWN;
60                         else if (str.compareTo("unknown") == 0)
61                                 return Piece.Type.UNKNOWN;
62
63                         throw new Exception("Piece.str2type - string " + str + " isn't a valid type");
64                                 
65                 }
66                 public static Piece.Colour str2colour(String str) throws Exception
67                 {
68                         if (str.compareTo("white") == 0)
69                                 return Piece.Colour.WHITE;
70                         else if (str.compareTo("black") == 0)
71                                 return Piece.Colour.BLACK;
72                         
73
74                         throw new Exception("Piece.str2colour - string " + str + " isn't a valid colour");
75                 }
76 }
77

UCC git Repository :: git.ucc.asn.au