From bd51b77da582869dbffcc49f83132430a4f0ff76 Mon Sep 17 00:00:00 2001 From: Arkadiusz Hypki Date: Tue, 30 May 2023 16:50:34 +0200 Subject: [PATCH] 'Added first interface for Python' --- .gitignore | 2 ++ .../wmi/oop/chess/dummy/BasicStudent.java | 35 +++++++++++++++++-- .../hypki/wmi/oop/chess/ChessInterface.java | 5 +-- .../hypki/wmi/oop/chess/ChessMatchMain.java | 23 ++++-------- chess-python-interface/net/__init__.py | 0 chess-python-interface/net/hypki/__init__.py | 0 .../net/hypki/chess/ChessInterface.py | 11 ++++++ .../net/hypki/chess/__init__.py | 0 prosty-projekt-obiektowy-uwagi.txt | 7 +++- 9 files changed, 62 insertions(+), 21 deletions(-) create mode 100644 chess-python-interface/net/__init__.py create mode 100644 chess-python-interface/net/hypki/__init__.py create mode 100644 chess-python-interface/net/hypki/chess/ChessInterface.py create mode 100644 chess-python-interface/net/hypki/chess/__init__.py diff --git a/.gitignore b/.gitignore index e5c9913..60c9122 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/chess-java-interface-dummy/src/main/java/net/hypki/wmi/oop/chess/dummy/BasicStudent.java b/chess-java-interface-dummy/src/main/java/net/hypki/wmi/oop/chess/dummy/BasicStudent.java index 2012d27..07945b2 100644 --- a/chess-java-interface-dummy/src/main/java/net/hypki/wmi/oop/chess/dummy/BasicStudent.java +++ b/chess-java-interface-dummy/src/main/java/net/hypki/wmi/oop/chess/dummy/BasicStudent.java @@ -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"); } } diff --git a/chess-java-interface/src/main/java/net/hypki/wmi/oop/chess/ChessInterface.java b/chess-java-interface/src/main/java/net/hypki/wmi/oop/chess/ChessInterface.java index e65aada..cfee36c 100644 --- a/chess-java-interface/src/main/java/net/hypki/wmi/oop/chess/ChessInterface.java +++ b/chess-java-interface/src/main/java/net/hypki/wmi/oop/chess/ChessInterface.java @@ -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(); } diff --git a/chess-match/src/main/java/net/hypki/wmi/oop/chess/ChessMatchMain.java b/chess-match/src/main/java/net/hypki/wmi/oop/chess/ChessMatchMain.java index 913630a..c650b2e 100644 --- a/chess-match/src/main/java/net/hypki/wmi/oop/chess/ChessMatchMain.java +++ b/chess-match/src/main/java/net/hypki/wmi/oop/chess/ChessMatchMain.java @@ -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(null); - - if (nextMove == null) - break; - - nextMove = student2Black.nextMove(nextMove); - - if (nextMove == null) - break; - } + Tournament tournament = new Tournament(white, black); + + 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(); } } diff --git a/chess-python-interface/net/__init__.py b/chess-python-interface/net/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/chess-python-interface/net/hypki/__init__.py b/chess-python-interface/net/hypki/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/chess-python-interface/net/hypki/chess/ChessInterface.py b/chess-python-interface/net/hypki/chess/ChessInterface.py new file mode 100644 index 0000000..e3c985e --- /dev/null +++ b/chess-python-interface/net/hypki/chess/ChessInterface.py @@ -0,0 +1,11 @@ +''' +Created on May 30, 2023 + +@author: ahypki +''' +class ChessInterface: + def nextMove(self, opponentMove = None): + pass + + def printBoard(self): + pass \ No newline at end of file diff --git a/chess-python-interface/net/hypki/chess/__init__.py b/chess-python-interface/net/hypki/chess/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/prosty-projekt-obiektowy-uwagi.txt b/prosty-projekt-obiektowy-uwagi.txt index 70bfbfc..55cdce4 100644 --- a/prosty-projekt-obiektowy-uwagi.txt +++ b/prosty-projekt-obiektowy-uwagi.txt @@ -1,2 +1,7 @@ - każda klasa - osobny plik -- do gita nie wrzucamy skompilowanych plików \ No newline at end of file +- 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/ \ No newline at end of file