Compare commits

...

2 Commits

Author SHA1 Message Date
Arkadiusz Hypki
968c7f08e5 'Merging' 2023-05-30 16:51:19 +02:00
Arkadiusz Hypki
bd51b77da5 'Added first interface for Python' 2023-05-30 16:50:34 +02:00
10 changed files with 131 additions and 20 deletions

2
.gitignore vendored
View File

@ -11,3 +11,5 @@ chess-java-interface-dummy/target
chess-java-interface/.classpath
chess-java-interface/.project
chess-java-interface/target
chess-python-interface/.project
chess-python-interface/.pydevproject

View File

@ -1,16 +1,47 @@
package net.hypki.wmi.oop.chess.dummy;
import static java.lang.System.currentTimeMillis;
import java.time.LocalDate;
import java.time.Period;
import java.util.Random;
import net.hypki.wmi.oop.chess.ChessInterface;
public class BasicStudent implements ChessInterface {
private static final Random random = new Random(currentTimeMillis());
private final String name;
public BasicStudent() {
this.name = null;
}
public BasicStudent(String name) {
this.name = name;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return super.toString();
}
@Override
public String nextMove(String opponentMove) {
return opponentMove;
try {
Thread.currentThread().sleep(1000 * (random.nextInt(3)));
} catch (InterruptedException e) {
System.err.println("Cannot sleep " + e);
return null;
}
return "e" + (random.nextInt(7) + 1) + "-e" + (random.nextInt(7) + 1);
}
@Override
public void printBoard() {
System.out.println("Not implemented yet");
System.out.println("Printing board not implemented yet");
}
}

View File

@ -1,7 +1,8 @@
package net.hypki.wmi.oop.chess;
/**
* Interface for chess programs for the classes 'Programowanie obiektowe' for Java language
* Interface for chess programs for the classes 'Programowanie obiektowe' for
* Java language
*
*/
public interface ChessInterface {
@ -11,6 +12,6 @@ public interface ChessInterface {
* @return
*/
public String nextMove(String opponentMove);
public void printBoard();
}

View File

@ -6,28 +6,19 @@ public class ChessMatchMain {
public static void main(String[] args) {
System.out.println("Preparing chess interface...");
ChessInterface student1White = new BasicStudent();
ChessInterface student2Black = new BasicStudent();
ChessInterface white = new BasicStudent();
ChessInterface black = new BasicStudent();
String nextMove = null;
while (true) {
nextMove = student1White.nextMove(nextMove);
Tournament tournament = new Tournament(white, black);
if (nextMove == null)
break;
nextMove = student2Black.nextMove(nextMove);
if (nextMove == null)
break;
}
tournament.run();
System.out.println("Match finished!");
System.out.println("Student1 board:");
student1White.printBoard();
white.printBoard();
System.out.println("Student2 board:");
student2Black.printBoard();
black.printBoard();
}
}

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

View File

View File

@ -0,0 +1,11 @@
'''
Created on May 30, 2023
@author: ahypki
'''
class ChessInterface:
def nextMove(self, opponentMove = None):
pass
def printBoard(self):
pass

View File

@ -1,2 +1,7 @@
- każda klasa - osobny plik
- do gita nie wrzucamy skompilowanych plików
- do gita nie wrzucamy skompilowanych plików
- dodać limit czasowy na jeden ruch: 1 minuta i niech to będzie parametr
- ja musze dodać jednak walidator bo mi studenci kombinują
https://www.developer.com/design/top-10-java-coding-guidelines/