493
|
1 |
// Resit about the Shogun Board Game
|
|
2 |
//====================================
|
|
3 |
|
|
4 |
// Task 1 - 6 see below
|
476
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
5 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
6 |
object M4 {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
7 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
8 |
type Pos = (Int, Int) // a position on a chessboard
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
9 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
10 |
// Colours: Red or White
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
11 |
abstract class Colour
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
12 |
case object Red extends Colour
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
13 |
case object Wht extends Colour
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
14 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
15 |
// Pieces: Either Pawns or Kings
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
16 |
//===============================
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
17 |
abstract class Piece {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
18 |
def pos : Pos
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
19 |
def col : Colour
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
20 |
def en : Int // energy for Pawns 1 - 4, for Kings 1 - 2
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
21 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
22 |
case class Pawn(en: Int, col: Colour, pos: Pos) extends Piece
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
23 |
case class King(en: Int, col: Colour, pos: Pos) extends Piece
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
24 |
|
493
|
25 |
// how to extract components from pieces
|
476
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
26 |
//val p = Pawn(4, Wht, (3,2))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
27 |
//assert(p.pos == (3,2))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
28 |
//assert(p.col == Wht)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
29 |
//assert(p.en == 4)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
30 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
31 |
// checks if a piece is a king
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
32 |
def is_king(pc: Piece) : Boolean = pc match {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
33 |
case King(_, _, _) => true
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
34 |
case _ => false
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
35 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
36 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
37 |
// incrementing and decrementing the position of a piece
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
38 |
def incx(pc: Piece) : Piece = pc match {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
39 |
case Pawn(en, c, (x,y)) => Pawn(en, c, (x+1,y))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
40 |
case King(en, c, (x,y)) => King(en, c, (x+1,y))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
41 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
42 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
43 |
def incy(pc: Piece) : Piece = pc match {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
44 |
case Pawn(en, c, (x,y)) => Pawn(en, c, (x,y+1))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
45 |
case King(en, c, (x,y)) => King(en, c, (x,y+1))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
46 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
47 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
48 |
def decx(pc: Piece) : Piece = pc match {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
49 |
case Pawn(en, c, (x,y)) => Pawn(en, c, (x-1,y))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
50 |
case King(en, c, (x,y)) => King(en, c, (x-1,y))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
51 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
52 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
53 |
def decy(pc: Piece) : Piece = pc match {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
54 |
case Pawn(en, c, (x,y)) => Pawn(en, c, (x,y-1))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
55 |
case King(en, c, (x,y)) => King(en, c, (x,y-1))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
56 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
57 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
58 |
//pretty printing colours and pieces
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
59 |
def pp_color(c: Colour) : String = c match {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
60 |
case Red => "R"
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
61 |
case Wht => "W"
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
62 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
63 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
64 |
def pp(pc: Piece) : String = pc match {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
65 |
case Pawn(n, c, _) => s"P${pp_color(c)}$n"
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
66 |
case King(n, c, _) => s"K${pp_color(c)}$n"
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
67 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
68 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
69 |
// Boards are sets of pieces
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
70 |
//===========================
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
71 |
case class Board(pces: Set[Piece]) {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
72 |
def +(pc: Piece) : Board = Board(pces + pc)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
73 |
def -(pc: Piece) : Board = Board(pces - pc)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
74 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
75 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
76 |
// checking whether a position is occupied in a board
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
77 |
def occupied(p: Pos, b: Board) : Option[Piece] =
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
78 |
b.pces.find(p == _.pos)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
79 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
80 |
def occupied_by(p: Pos, b: Board) : Option[Colour] =
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
81 |
occupied(p, b).map(_.col)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
82 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
83 |
def is_occupied(p: Pos, b: Board) : Boolean =
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
84 |
occupied(p, b).isDefined
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
85 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
86 |
// is a position inside a board
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
87 |
def inside(p: Pos, b: Board): Boolean =
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
88 |
1 <= p._1 && 1 <= p._2 && p._1 <= 8 && p._2 <= 8
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
89 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
90 |
// pretty printing a board
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
91 |
def print_board(b: Board): Unit = {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
92 |
println()
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
93 |
for (i <- 8 to 1 by -1) {
|
493
|
94 |
println("----" * 8)
|
476
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
95 |
for (j <- 1 to 8) {
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
96 |
val opc = occupied((j,i), b)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
97 |
if (opc.isDefined) print(s"|${pp(opc.get)}")
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
98 |
else print("| ")
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
99 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
100 |
println("|")
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
101 |
}
|
493
|
102 |
println("----" * 8)
|
476
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
103 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
104 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
105 |
// example board: initial board
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
106 |
val b_init = Board(Set(King(2,Wht,(4,1)), King(1,Red,(5,8)),
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
107 |
Pawn(4,Wht,(1,1)), Pawn(4,Red,(1,8)),
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
108 |
Pawn(3,Wht,(2,1)), Pawn(2,Red,(2,8)),
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
109 |
Pawn(2,Wht,(3,1)), Pawn(3,Red,(3,8)),
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
110 |
Pawn(1,Wht,(5,1)), Pawn(1,Red,(4,8)),
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
111 |
Pawn(4,Wht,(6,1)), Pawn(3,Red,(6,8)),
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
112 |
Pawn(3,Wht,(7,1)), Pawn(1,Red,(7,8)),
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
113 |
Pawn(2,Wht,(8,1)), Pawn(3,Red,(8,8))))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
114 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
115 |
//print_board(b_init)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
116 |
// --------------------------------
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
117 |
// |PR4|PR2|PR3|PR1|KR1|PR3|PR1|PR3|
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
118 |
// --------------------------------
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
119 |
// | | | | | | | | |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
120 |
// --------------------------------
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
121 |
// | | | | | | | | |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
122 |
// --------------------------------
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
123 |
// | | | | | | | | |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
124 |
// --------------------------------
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
125 |
// | | | | | | | | |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
126 |
// --------------------------------
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
127 |
// | | | | | | | | |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
128 |
// --------------------------------
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
129 |
// | | | | | | | | |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
130 |
// --------------------------------
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
131 |
// |PW4|PW3|PW2|KW2|PW1|PW4|PW3|PW2|
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
132 |
// --------------------------------
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
133 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
134 |
// Moves
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
135 |
//=======
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
136 |
abstract class Move
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
137 |
case object U extends Move // up
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
138 |
case object D extends Move // down
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
139 |
case object R extends Move // right
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
140 |
case object L extends Move // left
|
493
|
141 |
case object RU extends Move // first right, then possibly up
|
|
142 |
case object LU extends Move // first left, then possibly up
|
|
143 |
case object RD extends Move // ...
|
476
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
144 |
case object LD extends Move
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
145 |
case object UR extends Move
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
146 |
case object UL extends Move
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
147 |
case object DR extends Move
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
148 |
case object DL extends Move
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
149 |
|
493
|
150 |
//======================
|
|
151 |
// ADD YOUR CODE BELOW
|
|
152 |
//======================
|
|
153 |
|
|
154 |
|
|
155 |
// Task 1:
|
476
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
156 |
def eval(pc: Piece, m: Move, en: Int, b: Board) : Set[Piece] = {
|
493
|
157 |
val pos = pc.pos
|
|
158 |
if (!inside(pos, b)) then Set()
|
|
159 |
else if (en == 0) then
|
|
160 |
if is_occupied(pos, b) then
|
|
161 |
val occupant = occupied_by(pos, b)
|
|
162 |
if occupant.get != pc.col then
|
|
163 |
Set(pc)
|
|
164 |
else Set()
|
|
165 |
else Set(pc)
|
|
166 |
else if (is_occupied(pos,b)) then Set()
|
|
167 |
else {m match {
|
|
168 |
case U => eval(incy(pc), U, en-1, b)
|
|
169 |
case D => eval(decy(pc), D, en-1, b)
|
|
170 |
case R => eval(incx(pc), R, en-1, b)
|
|
171 |
case L => eval(decx(pc), L, en-1, b)
|
|
172 |
case RU => eval(incx(pc), RU, en-1, b) ++ eval(pc, U, en, b)
|
|
173 |
case LU => eval(decx(pc), LU, en-1, b) ++ eval(pc, U, en, b)
|
|
174 |
case RD => eval(incx(pc), RD, en-1, b) ++ eval(pc, D, en, b)
|
|
175 |
case LD => eval(decx(pc), LD, en-1, b) ++ eval(pc, D, en, b)
|
|
176 |
case UR => eval(incy(pc), UR, en-1, b) ++ eval(pc, R, en, b)
|
|
177 |
case UL => eval(incy(pc), UL, en-1, b) ++ eval(pc, L, en, b)
|
|
178 |
case DR => eval(decy(pc), DR, en-1, b) ++ eval(pc, R, en, b)
|
|
179 |
case DL => eval(decy(pc), DL, en-1, b) ++ eval(pc, L, en, b)
|
|
180 |
}
|
|
181 |
}
|
|
182 |
}
|
476
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
183 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
184 |
|
493
|
185 |
// Task 2:
|
476
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
186 |
def all_moves(pc: Piece, b: Board) : Set[Piece] = {
|
493
|
187 |
val temporary_board = b - pc //not sure if this is
|
|
188 |
//what was meant by changes to the board (Perth discussion on keats)
|
|
189 |
val all_possible_moves = Set(U, D, R, L, RU, LU, RD, LD, UR, UL, DR, DL)
|
|
190 |
all_possible_moves.flatMap(move => eval(pc, move, pc.en, temporary_board))
|
|
191 |
}
|
|
192 |
|
|
193 |
|
|
194 |
// Task 3:
|
|
195 |
def attacked(c: Colour, b: Board) : Set[Piece] = {
|
|
196 |
val my_pieces = b.pces.filter(_.col == c)
|
|
197 |
val opponent_pieces = b.pces.filter(_.col != c)
|
|
198 |
val attacked_pieces = opponent_pieces.filter(pc => my_pieces.flatMap(p => all_moves(p, b)).exists(_.pos == pc.pos))
|
|
199 |
attacked_pieces
|
|
200 |
}
|
|
201 |
|
|
202 |
|
|
203 |
// Task 4:
|
|
204 |
def attackedN(pc: Piece, b: Board) : Int = {
|
|
205 |
val opponent_pieces = b.pces.filter(_.col != pc.col)
|
|
206 |
val attacking_pieces_num = opponent_pieces.count(p => all_moves(p, b).exists(_.pos == pc.pos))
|
|
207 |
attacking_pieces_num
|
|
208 |
}
|
|
209 |
|
|
210 |
|
|
211 |
// Task 5:
|
|
212 |
def protectedN(pc: Piece, b: Board) : Int = {
|
|
213 |
val temporary_board = b - pc
|
|
214 |
val my_pieces = b.pces.filter(_.col == pc.col)
|
|
215 |
val protecting_pieces_num = my_pieces.count(p => all_moves(p, temporary_board).exists(_.pos == pc.pos))
|
|
216 |
protecting_pieces_num
|
|
217 |
}
|
|
218 |
|
|
219 |
|
|
220 |
// Task 6:
|
|
221 |
def legal_moves(pc: Piece, b: Board) : Set[Piece] = {
|
|
222 |
if is_king(pc) then
|
|
223 |
val all_king_moves = all_moves(pc, b)
|
|
224 |
val valid_king_moves = all_king_moves.filter{m =>
|
|
225 |
val temporary_board = Board(b.pces.filter(_.pos != m.pos))//remove potentially captured pieces
|
|
226 |
val updated_temp_board = temporary_board + m
|
|
227 |
val opponent_pieces = updated_temp_board.pces.filter(_.col != pc.col)
|
|
228 |
val opponent_moves = opponent_pieces.flatMap(p => all_moves(p, updated_temp_board))
|
|
229 |
!(opponent_moves.exists(_.pos == m.pos))}
|
|
230 |
valid_king_moves
|
|
231 |
else {all_moves(pc, b)}
|
476
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
232 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
233 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
234 |
/*
|
493
|
235 |
// more test cases
|
|
236 |
//=================
|
476
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
237 |
val pw1 = Pawn(4, Wht, (4,6))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
238 |
val pw2 = Pawn(4, Wht, (2,4))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
239 |
val pw3 = Pawn(3, Red, (6,8))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
240 |
val pw4 = Pawn(2, Red, (2,8))
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
241 |
val bt = b_init + pw1 + pw2
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
242 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
243 |
print_board(bt)
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
244 |
println(s"Capture Red: ${attacked(Wht, bt)}")
|
493
|
245 |
// => Set(Pawn(2,Red,(2,8)), Pawn(3,Red,(6,8)))
|
|
246 |
|
476
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
247 |
println(s"Capture Wht: ${attacked(Red, bt)}")
|
493
|
248 |
// => Set(Pawn(4,Wht,(4,6)))
|
|
249 |
|
476
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
250 |
println(s"ProtectedN: ${protectedN(pw3, bt)}")
|
493
|
251 |
// => 2
|
|
252 |
|
476
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
253 |
println(s"AttackedN: ${attackedN(pw4, bt)}")
|
493
|
254 |
// => 2
|
|
255 |
|
476
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
256 |
println(s"all moves: ${all_moves(pw2, bt)}")
|
493
|
257 |
// => Set(Pawn(4,Wht,(4,2)), Pawn(4,Wht,(1,7)), Pawn(4,Wht,(5,3)), Pawn(4,Wht,(5,5)),
|
|
258 |
// Pawn(4,Wht,(2,8)), Pawn(4,Wht,(3,7)), Pawn(4,Wht,(6,4)))
|
|
259 |
*/
|
476
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
260 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
261 |
}
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
262 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
263 |
|