'Merging'

This commit is contained in:
Arkadiusz Hypki 2023-05-30 16:51:19 +02:00
commit 968c7f08e5
2 changed files with 71 additions and 1 deletions

View File

@ -10,7 +10,7 @@ public class ChessMatchMain {
ChessInterface black = new BasicStudent();
Tournament tournament = new Tournament(white, black);
tournament.run();
System.out.println("Match finished!");

View File

@ -0,0 +1,70 @@
package net.hypki.wmi.oop.chess;
public class Tournament {
private ChessInterface white;
private ChessInterface black;
public Tournament() {
}
public Tournament(ChessInterface white, ChessInterface black) {
setWhite(white);
setBlack(black);
}
public ChessInterface getWhite() {
return white;
}
public void setWhite(ChessInterface white) {
this.white = white;
}
public ChessInterface getBlack() {
return black;
}
public void setBlack(ChessInterface black) {
this.black = black;
}
public void run() {
String nextMove = null;
while (true) {
nextMove = getWhite().nextMove(null);
if (nextMove == null)
break;
System.out.println("Next move: " + nextMove);
nextMove = getBlack().nextMove(nextMove);
if (nextMove == null)
break;
System.out.println("Next move: " + nextMove);
}
}
private String nextMove(ChessInterface chessInterface, String nextMove) {
try {
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
}
});
return chessInterface.nextMove(nextMove);
} catch (Throwable t) {
System.err.println(t);
return null;
}
}
}