Skip to content

Commit 5c74030

Browse files
author
Hugo
committed
Squelettes final des requêtes Platforme -> IA
1 parent c7c103d commit 5c74030

File tree

15 files changed

+339
-59
lines changed

15 files changed

+339
-59
lines changed

BoutsDeCode/DameRESTJava/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<artifactId>javax.servlet-api</artifactId>
4545
<version>${servlet.api.version}</version>
4646
</dependency>
47-
47+
4848
<dependency>
4949
<groupId>com.fasterxml.jackson.core</groupId>
5050
<artifactId>jackson-databind</artifactId>
@@ -53,7 +53,7 @@
5353
</dependencies>
5454

5555
<build>
56-
<finalName>rest-ws</finalName>
56+
<finalName>WebServiceIa</finalName>
5757
<plugins>
5858
<!-- Configuration du plugin de compilation -->
5959
<plugin>
Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,50 @@
11
package controller;
22

3-
import org.springframework.http.HttpStatus;
4-
import org.springframework.http.ResponseEntity;
3+
import org.springframework.web.bind.annotation.PathVariable;
54
import org.springframework.web.bind.annotation.RequestBody;
65
import org.springframework.web.bind.annotation.RequestMapping;
76
import org.springframework.web.bind.annotation.RequestMethod;
87
import org.springframework.web.bind.annotation.RestController;
9-
import org.springframework.web.client.RestTemplate;
8+
import model.STATUS;
9+
import paquetsJSON.EntreeIaGamesEndId;
10+
import paquetsJSON.EntreeIaGamesStart;
11+
import paquetsJSON.EntreeIaStatus;
12+
import paquetsJSON.EntreeRetourIaGamePlayId;
13+
import paquetsJSON.RetourIaGamesEndId;
14+
import paquetsJSON.RetourIaGamesStart;
15+
import paquetsJSON.RetourIaStatus;
1016

11-
import model.Board;
1217

1318
@RestController
1419
public class DameController {
1520

16-
private static String URL ="http://localhost:8080/rest-ws";
17-
18-
@RequestMapping(value = "/", method = RequestMethod.GET)
19-
public String home() {
20-
return "hello Dame";
21+
@RequestMapping(value = "/ai/status", method = RequestMethod.POST)
22+
public RetourIaStatus status(@RequestBody EntreeIaStatus token) {
23+
//TODO Demander l'état d'une IA
24+
//test de retour
25+
return new RetourIaStatus(token.getToken(), STATUS.available);
2126
}
2227

23-
/*
24-
* Retourne un objet Board serializé en Json
25-
*/
26-
@RequestMapping(value="/basicBoard", method=RequestMethod.GET)
27-
public Board getBoard() {
28-
//RestTemplate rest = new RestTemplate();
29-
char[] board = {'1','2','3'};
30-
Board b = new Board(board);
31-
return b;
28+
29+
@RequestMapping(value="/ai/games/start/", method = RequestMethod.POST)
30+
public RetourIaGamesStart beginGame(@RequestBody EntreeIaGamesStart e) {
31+
//TODO Prévenir les IA qu’une partie les concernant va commencer
32+
//test de retour
33+
return new RetourIaGamesStart(e.getToken(), STATUS.available, "testTokenPartie");
3234
}
3335

34-
/*
35-
* Attend un flux Json en entrée,
36-
* le convertie en objet Board Java et le
37-
* retourne de nouveau en tant que Json
38-
*/
39-
40-
@RequestMapping(value = "/sendAndReturnBoardJson", method = RequestMethod.POST)
41-
public Board update(@RequestBody Board b) {
42-
// TODO: call persistence layer to update
43-
return new ResponseEntity<Board>(b, HttpStatus.OK).getBody();
36+
@RequestMapping(value = "/ai/games/play/{game_id:.+}", method = RequestMethod.POST)
37+
public EntreeRetourIaGamePlayId getMove(@PathVariable("game_id") String game_id, @RequestBody EntreeRetourIaGamePlayId e) {
38+
// TODO: Demande de jouer un coup sur un plateau donnée sur une partie
39+
//test de retour
40+
return new EntreeRetourIaGamePlayId(e.getToken(), e.getDifficulty(), e.getPlayer(), e.getBoard());
4441
}
4542

46-
/*
47-
* Va chercher un flux json à l'url donnée, le convertie en Board
48-
* et le retourne en le reconvertisant en Json
49-
*/
50-
@RequestMapping(value="/TestRecupData", method=RequestMethod.GET)
51-
public Board getBoardSend() {
52-
RestTemplate rest = new RestTemplate();
53-
Board b2 = rest.getForObject(URL + "/basicBoard", Board.class);
54-
return b2;
43+
@RequestMapping(value="/ai/games/end/{game_id:.+}", method=RequestMethod.POST)
44+
public RetourIaGamesEndId endGame(@PathVariable("game_id") String game_id, @RequestBody EntreeIaGamesEndId e) {
45+
// TODO: Annoncer la fin de partie avec code explicatif pour gérer les parties avortées et les parties standards.
46+
//test de retour
47+
return new RetourIaGamesEndId (game_id + " " + e.getToken(), STATUS.available);
5548
}
5649

5750
}

BoutsDeCode/DameRESTJava/src/main/java/model/Board.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ public Board() {
1919
board = new char[50];
2020
for (int i = 0; i < 50; ++i) {
2121
if (i <= 19) {
22-
board[i] = '1';
22+
board[i] = CASE.BLACK_PAWN.getCharRepresentation();
2323
}
2424
else if (i > 19 && i < 35) {
25-
board[i] = '0';
25+
board[i] = CASE.EMPTY.getCharRepresentation();
2626
}
2727
else {
28-
board[i] = '3';
28+
board[i] = CASE.WHITE_PAWN.getCharRepresentation();
2929
}
3030
}
3131
}
@@ -37,4 +37,5 @@ public Board(char[] tabB) {
3737
public char[] getBoard() {
3838
return board;
3939
}
40+
4041
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package model;
2+
3+
public enum CODEENDGAME {
4+
timeout,
5+
surrender,
6+
classical
7+
}
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
package model;
22

3-
public enum Case {
4-
EMPTY(0), // '\0'
5-
BLACK_PAWN(1), // '\1'
6-
BLACK_DRAUGHT(2), // '\2'
7-
WHITE_PAWN(3), // '\3'
8-
WHITE_DRAUGHT(4); // '\4'
3+
public enum CASE {
4+
EMPTY('0'), // '\0'
5+
BLACK_PAWN('1'), // '\1'
6+
BLACK_DRAUGHT('2'), // '\2'
7+
WHITE_PAWN('3'), // '\3'
8+
WHITE_DRAUGHT('4'); // '\4'
99

10-
private int integerRepresentation;
10+
private char charRepresentation;
1111

12-
private Case(int i) {
13-
integerRepresentation = i;
12+
private CASE(char c) {
13+
charRepresentation = c;
1414
}
1515

16-
public int getIntegerRepresentation() {
17-
return integerRepresentation;
16+
public char getCharRepresentation() {
17+
return this.charRepresentation;
1818
}
19+
1920
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package model;
22

3-
public enum Difficulte {
4-
5-
}
3+
public enum DIFFICULTE {
4+
EASY,
5+
MEDIUM,
6+
HARD;
7+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package model;
22

3-
public enum Joueur {
3+
public enum JOUEUR {
44
J1, // joueur 1, blanc
55
J2, // joueur 2, noir
6-
DRAW // aucun des joueurs
6+
DRAW; // aucun des joueurs
77
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package model;
22

3-
public enum Status {
3+
public enum STATUS {
44
busy,
55
available
66
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package paquetsJSON;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
import model.CODEENDGAME;
7+
import model.JOUEUR;
8+
9+
public class EntreeIaGamesEndId {
10+
11+
private String token;
12+
private JOUEUR winner;
13+
private CODEENDGAME code;
14+
15+
@JsonCreator
16+
public EntreeIaGamesEndId(@JsonProperty("token")String t, @JsonProperty("winner")JOUEUR w, @JsonProperty("code")CODEENDGAME c) {
17+
token = t;
18+
winner = w;
19+
code = c;
20+
}
21+
22+
public String getToken() {
23+
return token;
24+
}
25+
26+
public JOUEUR getWinner() {
27+
return winner;
28+
}
29+
30+
public CODEENDGAME getCode() {
31+
return code;
32+
}
33+
34+
public void setToken(String token) {
35+
this.token = token;
36+
}
37+
38+
public void setWinner(JOUEUR winner) {
39+
this.winner = winner;
40+
}
41+
42+
public void setCode(CODEENDGAME code) {
43+
this.code = code;
44+
}
45+
46+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package paquetsJSON;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
import model.DIFFICULTE;
7+
import model.JOUEUR;
8+
9+
public class EntreeIaGamesStart {
10+
11+
private String token;
12+
private DIFFICULTE difficulty;
13+
private JOUEUR player;
14+
15+
@JsonCreator
16+
public EntreeIaGamesStart(@JsonProperty("token")String t, @JsonProperty("difficulty")DIFFICULTE d, @JsonProperty("player")JOUEUR p) {
17+
token = t;
18+
difficulty = d;
19+
player = p;
20+
}
21+
22+
public String getToken() {
23+
return token;
24+
}
25+
public DIFFICULTE getDifficulty() {
26+
return difficulty;
27+
}
28+
public JOUEUR getPlayer() {
29+
return player;
30+
}
31+
32+
public void setToken(String token) {
33+
this.token = token;
34+
}
35+
36+
public void setDifficulty(DIFFICULTE difficulty) {
37+
this.difficulty = difficulty;
38+
}
39+
40+
public void setPlayer(JOUEUR player) {
41+
this.player = player;
42+
}
43+
}

0 commit comments

Comments
 (0)