rename Piece to Stone
This commit is contained in:
parent
1f2ff242e4
commit
9144683de3
@ -18,7 +18,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
|
|
||||||
import djmil.cordacheckers.cordaclient.dao.GameState;
|
import djmil.cordacheckers.cordaclient.dao.GameState;
|
||||||
import djmil.cordacheckers.cordaclient.dao.HoldingIdentity;
|
import djmil.cordacheckers.cordaclient.dao.HoldingIdentity;
|
||||||
import djmil.cordacheckers.cordaclient.dao.Piece;
|
import djmil.cordacheckers.cordaclient.dao.Stone;
|
||||||
import djmil.cordacheckers.cordaclient.dao.Rank;
|
import djmil.cordacheckers.cordaclient.dao.Rank;
|
||||||
import djmil.cordacheckers.cordaclient.dao.VirtualNode;
|
import djmil.cordacheckers.cordaclient.dao.VirtualNode;
|
||||||
import djmil.cordacheckers.cordaclient.dao.VirtualNodeList;
|
import djmil.cordacheckers.cordaclient.dao.VirtualNodeList;
|
||||||
@ -95,7 +95,7 @@ public class CordaClient {
|
|||||||
.getResponce(requestBody);
|
.getResponce(requestBody);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameState gameProposalCreate(HoldingIdentity issuer, HoldingIdentity acquier, Piece.Color acquierColor,
|
public GameState gameProposalCreate(HoldingIdentity issuer, HoldingIdentity acquier, Stone.Color acquierColor,
|
||||||
String message
|
String message
|
||||||
) {
|
) {
|
||||||
final RequestBody requestBody = new RequestBody(
|
final RequestBody requestBody = new RequestBody(
|
||||||
|
@ -7,9 +7,9 @@ import java.util.UUID;
|
|||||||
public record GameState(
|
public record GameState(
|
||||||
Status status,
|
Status status,
|
||||||
String opponentName,
|
String opponentName,
|
||||||
Piece.Color opponentColor,
|
Stone.Color opponentColor,
|
||||||
|
|
||||||
Map<Integer, Piece> board,
|
Map<Integer, Stone> board,
|
||||||
Integer moveNumber,
|
Integer moveNumber,
|
||||||
List<Integer> previousMove,
|
List<Integer> previousMove,
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package djmil.cordacheckers.cordaclient.dao;
|
package djmil.cordacheckers.cordaclient.dao;
|
||||||
|
|
||||||
public class Piece {
|
public class Stone {
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
MAN,
|
MAN,
|
||||||
@ -19,12 +19,12 @@ public class Piece {
|
|||||||
Color color;
|
Color color;
|
||||||
Type type;
|
Type type;
|
||||||
|
|
||||||
public Piece() {
|
public Stone() {
|
||||||
this.color = null;
|
this.color = null;
|
||||||
this.type = null;
|
this.type = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Piece(Color color, Type type) {
|
public Stone(Color color, Type type) {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ public class Piece {
|
|||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
Piece other = (Piece) obj;
|
Stone other = (Stone) obj;
|
||||||
if (color != other.color)
|
if (color != other.color)
|
||||||
return false;
|
return false;
|
||||||
if (type != other.type)
|
if (type != other.type)
|
@ -1,10 +1,10 @@
|
|||||||
package djmil.cordacheckers.cordaclient.dao.flow.arguments;
|
package djmil.cordacheckers.cordaclient.dao.flow.arguments;
|
||||||
|
|
||||||
import djmil.cordacheckers.cordaclient.dao.Piece;
|
import djmil.cordacheckers.cordaclient.dao.Stone;
|
||||||
|
|
||||||
public record ReqGameProposalCreate(
|
public record ReqGameProposalCreate(
|
||||||
String opponentName,
|
String opponentName,
|
||||||
Piece.Color opponentColor,
|
Stone.Color opponentColor,
|
||||||
String message
|
String message
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ import com.fasterxml.jackson.databind.JsonMappingException;
|
|||||||
import djmil.cordacheckers.cordaclient.CordaClient;
|
import djmil.cordacheckers.cordaclient.CordaClient;
|
||||||
import djmil.cordacheckers.cordaclient.dao.GameState;
|
import djmil.cordacheckers.cordaclient.dao.GameState;
|
||||||
import djmil.cordacheckers.cordaclient.dao.HoldingIdentity;
|
import djmil.cordacheckers.cordaclient.dao.HoldingIdentity;
|
||||||
import djmil.cordacheckers.cordaclient.dao.Piece;
|
import djmil.cordacheckers.cordaclient.dao.Stone;
|
||||||
import djmil.cordacheckers.cordaclient.dao.flow.arguments.ReqGameProposalCreate;
|
import djmil.cordacheckers.cordaclient.dao.flow.arguments.ReqGameProposalCreate;
|
||||||
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
||||||
import djmil.cordacheckers.user.User;
|
import djmil.cordacheckers.user.User;
|
||||||
@ -59,7 +59,7 @@ public class GameProposalController {
|
|||||||
final HoldingIdentity gpSender = sender.getHoldingIdentity();
|
final HoldingIdentity gpSender = sender.getHoldingIdentity();
|
||||||
// TODO: throw execption with custom type
|
// TODO: throw execption with custom type
|
||||||
final HoldingIdentity gpReceiver = holdingIdentityResolver.getByUsername(gpRequest.opponentName());
|
final HoldingIdentity gpReceiver = holdingIdentityResolver.getByUsername(gpRequest.opponentName());
|
||||||
final Piece.Color gpReceiverColor = gpRequest.opponentColor();
|
final Stone.Color gpReceiverColor = gpRequest.opponentColor();
|
||||||
|
|
||||||
// TODO handle expectionns here
|
// TODO handle expectionns here
|
||||||
GameState gameStateView = cordaClient.gameProposalCreate(
|
GameState gameStateView = cordaClient.gameProposalCreate(
|
||||||
|
@ -12,7 +12,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|||||||
|
|
||||||
import djmil.cordacheckers.cordaclient.dao.GameState;
|
import djmil.cordacheckers.cordaclient.dao.GameState;
|
||||||
import djmil.cordacheckers.cordaclient.dao.GameState.Status;
|
import djmil.cordacheckers.cordaclient.dao.GameState.Status;
|
||||||
import djmil.cordacheckers.cordaclient.dao.Piece;
|
import djmil.cordacheckers.cordaclient.dao.Stone;
|
||||||
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ -26,10 +26,10 @@ public class GameBoardTests {
|
|||||||
final String whitePlayerName = "alice";
|
final String whitePlayerName = "alice";
|
||||||
final String blackPlayerName = "bob";
|
final String blackPlayerName = "bob";
|
||||||
|
|
||||||
final static Piece WHITE_MAN = new Piece(Piece.Color.WHITE, Piece.Type.MAN);
|
final static Stone WHITE_MAN = new Stone(Stone.Color.WHITE, Stone.Type.MAN);
|
||||||
final static Piece WHITE_KING = new Piece(Piece.Color.WHITE, Piece.Type.KING);
|
final static Stone WHITE_KING = new Stone(Stone.Color.WHITE, Stone.Type.KING);
|
||||||
final static Piece BLACK_MAN = new Piece(Piece.Color.BLACK, Piece.Type.MAN);
|
final static Stone BLACK_MAN = new Stone(Stone.Color.BLACK, Stone.Type.MAN);
|
||||||
final static Piece BLACK_KING = new Piece(Piece.Color.BLACK, Piece.Type.KING);
|
final static Stone BLACK_KING = new Stone(Stone.Color.BLACK, Stone.Type.KING);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSurrender() {
|
void testSurrender() {
|
||||||
@ -38,14 +38,14 @@ public class GameBoardTests {
|
|||||||
final String message = "GameBoard SURRENDER test";
|
final String message = "GameBoard SURRENDER test";
|
||||||
|
|
||||||
final GameState game = cordaClient.gameProposalCreate(
|
final GameState game = cordaClient.gameProposalCreate(
|
||||||
hiWhite, hiBlack, Piece.Color.BLACK, message);
|
hiWhite, hiBlack, Stone.Color.BLACK, message);
|
||||||
|
|
||||||
System.out.println("Game UUID " +game.uuid());
|
System.out.println("Game UUID " +game.uuid());
|
||||||
|
|
||||||
final GameState acceptedGameBlackView = cordaClient.gameProposalAccept(
|
final GameState acceptedGameBlackView = cordaClient.gameProposalAccept(
|
||||||
hiBlack, game.uuid());
|
hiBlack, game.uuid());
|
||||||
|
|
||||||
assertThat(acceptedGameBlackView.opponentColor()).isEqualByComparingTo(Piece.Color.WHITE);
|
assertThat(acceptedGameBlackView.opponentColor()).isEqualByComparingTo(Stone.Color.WHITE);
|
||||||
assertThat(acceptedGameBlackView.status()).isEqualByComparingTo(Status.GAME_BOARD_WAIT_FOR_OPPONENT);
|
assertThat(acceptedGameBlackView.status()).isEqualByComparingTo(Status.GAME_BOARD_WAIT_FOR_OPPONENT);
|
||||||
|
|
||||||
assertThatThrownBy(() -> { // Black can not surrender, since it is opponent's turn
|
assertThatThrownBy(() -> { // Black can not surrender, since it is opponent's turn
|
||||||
@ -57,14 +57,14 @@ public class GameBoardTests {
|
|||||||
hiWhite, game.uuid());
|
hiWhite, game.uuid());
|
||||||
|
|
||||||
assertThat(surrendererGameView.opponentName()).isEqualToIgnoringCase(blackPlayerName);
|
assertThat(surrendererGameView.opponentName()).isEqualToIgnoringCase(blackPlayerName);
|
||||||
assertThat(surrendererGameView.opponentColor()).isEqualByComparingTo(Piece.Color.BLACK);
|
assertThat(surrendererGameView.opponentColor()).isEqualByComparingTo(Stone.Color.BLACK);
|
||||||
assertThat(surrendererGameView.status()).isEqualByComparingTo(Status.GAME_RESULT_YOU_LOOSE);
|
assertThat(surrendererGameView.status()).isEqualByComparingTo(Status.GAME_RESULT_YOU_LOOSE);
|
||||||
|
|
||||||
final GameState winnerGameView = cordaClient.gameStateGet(
|
final GameState winnerGameView = cordaClient.gameStateGet(
|
||||||
hiBlack, game.uuid());
|
hiBlack, game.uuid());
|
||||||
|
|
||||||
assertThat(winnerGameView.opponentName()).isEqualToIgnoringCase(whitePlayerName);
|
assertThat(winnerGameView.opponentName()).isEqualToIgnoringCase(whitePlayerName);
|
||||||
assertThat(winnerGameView.opponentColor()).isEqualByComparingTo(Piece.Color.WHITE);
|
assertThat(winnerGameView.opponentColor()).isEqualByComparingTo(Stone.Color.WHITE);
|
||||||
assertThat(winnerGameView.status()).isEqualByComparingTo(Status.GAME_RESULT_YOU_WON);
|
assertThat(winnerGameView.status()).isEqualByComparingTo(Status.GAME_RESULT_YOU_WON);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ public class GameBoardTests {
|
|||||||
final String message = "GameBoard MOVE test";
|
final String message = "GameBoard MOVE test";
|
||||||
|
|
||||||
final GameState game = cordaClient.gameProposalCreate(
|
final GameState game = cordaClient.gameProposalCreate(
|
||||||
hiWhite, hiBlack, Piece.Color.BLACK, message);
|
hiWhite, hiBlack, Stone.Color.BLACK, message);
|
||||||
System.out.println("Game UUID " +game.uuid());
|
System.out.println("Game UUID " +game.uuid());
|
||||||
|
|
||||||
final var m0 = cordaClient.gameProposalAccept(hiBlack, game.uuid());
|
final var m0 = cordaClient.gameProposalAccept(hiBlack, game.uuid());
|
||||||
|
@ -10,7 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|||||||
|
|
||||||
import djmil.cordacheckers.cordaclient.dao.GameState;
|
import djmil.cordacheckers.cordaclient.dao.GameState;
|
||||||
import djmil.cordacheckers.cordaclient.dao.GameState.Status;
|
import djmil.cordacheckers.cordaclient.dao.GameState.Status;
|
||||||
import djmil.cordacheckers.cordaclient.dao.Piece;
|
import djmil.cordacheckers.cordaclient.dao.Stone;
|
||||||
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ -23,7 +23,7 @@ public class GameProposalTests {
|
|||||||
|
|
||||||
final String issuer = "alice";
|
final String issuer = "alice";
|
||||||
final String acquier = "bob";
|
final String acquier = "bob";
|
||||||
final Piece.Color acquierColor = Piece.Color.WHITE;
|
final Stone.Color acquierColor = Stone.Color.WHITE;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCreate() {
|
void testCreate() {
|
||||||
|
@ -8,7 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
import djmil.cordacheckers.cordaclient.dao.GameState;
|
import djmil.cordacheckers.cordaclient.dao.GameState;
|
||||||
import djmil.cordacheckers.cordaclient.dao.Piece;
|
import djmil.cordacheckers.cordaclient.dao.Stone;
|
||||||
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ -21,7 +21,7 @@ public class GameStateTests {
|
|||||||
|
|
||||||
final String issuer = "alice";
|
final String issuer = "alice";
|
||||||
final String acquier = "bob";
|
final String acquier = "bob";
|
||||||
final Piece.Color acquierColor = Piece.Color.WHITE;
|
final Stone.Color acquierColor = Stone.Color.WHITE;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testList() {
|
void testList() {
|
||||||
|
@ -9,7 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
import djmil.cordacheckers.cordaclient.dao.GameState;
|
import djmil.cordacheckers.cordaclient.dao.GameState;
|
||||||
import djmil.cordacheckers.cordaclient.dao.Piece;
|
import djmil.cordacheckers.cordaclient.dao.Stone;
|
||||||
import djmil.cordacheckers.cordaclient.dao.Rank;
|
import djmil.cordacheckers.cordaclient.dao.Rank;
|
||||||
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ public class RankingTests {
|
|||||||
final var hiLooser = holdingIdentityResolver.getByUsername("Bob");
|
final var hiLooser = holdingIdentityResolver.getByUsername("Bob");
|
||||||
|
|
||||||
final GameState game = cordaClient.gameProposalCreate(
|
final GameState game = cordaClient.gameProposalCreate(
|
||||||
hiWinner, hiLooser, Piece.Color.WHITE, "GameBoard GLOBAL_RANKING test");
|
hiWinner, hiLooser, Stone.Color.WHITE, "GameBoard GLOBAL_RANKING test");
|
||||||
|
|
||||||
cordaClient.gameProposalAccept(hiLooser, game.uuid());
|
cordaClient.gameProposalAccept(hiLooser, game.uuid());
|
||||||
cordaClient.gameBoardSurrender(hiLooser, game.uuid());
|
cordaClient.gameBoardSurrender(hiLooser, game.uuid());
|
||||||
|
@ -10,17 +10,17 @@ import java.util.Map;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import djmil.cordacheckers.states.Piece;
|
import djmil.cordacheckers.states.Stone;
|
||||||
import djmil.cordacheckers.states.Piece.Color;
|
import djmil.cordacheckers.states.Stone.Color;
|
||||||
import net.corda.v5.ledger.utxo.transaction.UtxoLedgerTransaction;
|
import net.corda.v5.ledger.utxo.transaction.UtxoLedgerTransaction;
|
||||||
|
|
||||||
public class GameBoardContract implements net.corda.v5.ledger.utxo.Contract {
|
public class GameBoardContract implements net.corda.v5.ledger.utxo.Contract {
|
||||||
|
|
||||||
public static class MoveResult {
|
public static class MoveResult {
|
||||||
final public Map<Integer, Piece> board;
|
final public Map<Integer, Stone> board;
|
||||||
final public Piece.Color moveColor;
|
final public Stone.Color moveColor;
|
||||||
|
|
||||||
public MoveResult(Map<Integer, Piece> board, Color moveColor) {
|
public MoveResult(Map<Integer, Stone> board, Color moveColor) {
|
||||||
this.board = board;
|
this.board = board;
|
||||||
this.moveColor = moveColor;
|
this.moveColor = moveColor;
|
||||||
}
|
}
|
||||||
@ -59,11 +59,11 @@ public class GameBoardContract implements net.corda.v5.ledger.utxo.Contract {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MoveResult applyMove(List<Integer> move, Map<Integer, Piece> board, Piece.Color moveColor) {
|
public static MoveResult applyMove(List<Integer> move, Map<Integer, Stone> board, Stone.Color moveColor) {
|
||||||
final int mFrom = move.get(0);
|
final int mFrom = move.get(0);
|
||||||
final int mTo = move.get(1);
|
final int mTo = move.get(1);
|
||||||
|
|
||||||
final Piece piece = board.get(mFrom);
|
final Stone piece = board.get(mFrom);
|
||||||
if (piece == null)
|
if (piece == null)
|
||||||
throw new MoveResult.Exception("An empty starting tile");
|
throw new MoveResult.Exception("An empty starting tile");
|
||||||
|
|
||||||
@ -73,45 +73,40 @@ public class GameBoardContract implements net.corda.v5.ledger.utxo.Contract {
|
|||||||
if (board.get(mTo) != null)
|
if (board.get(mTo) != null)
|
||||||
throw new MoveResult.Exception("An occupied finishing tile");
|
throw new MoveResult.Exception("An occupied finishing tile");
|
||||||
|
|
||||||
final Map<Integer, Piece> newBoard = new LinkedHashMap<Integer, Piece>(board);
|
final Map<Integer, Stone> newBoard = new LinkedHashMap<Integer, Stone>(board);
|
||||||
newBoard.remove(mFrom);
|
newBoard.remove(mFrom);
|
||||||
newBoard.put(mTo, piece);
|
newBoard.put(mTo, piece);
|
||||||
|
|
||||||
return new GameBoardContract.MoveResult(newBoard, moveColor.opposite());
|
return new GameBoardContract.MoveResult(newBoard, moveColor.opposite());
|
||||||
}
|
}
|
||||||
|
|
||||||
final static Piece WHITE_MAN = new Piece(Piece.Color.WHITE, Piece.Type.MAN);
|
public final static Map<Integer, Stone> initialBoard = Map.ofEntries(
|
||||||
final static Piece WHITE_KING = new Piece(Piece.Color.WHITE, Piece.Type.KING);
|
|
||||||
final static Piece BLACK_MAN = new Piece(Piece.Color.BLACK, Piece.Type.MAN);
|
|
||||||
final static Piece BLACK_KING = new Piece(Piece.Color.BLACK, Piece.Type.KING);
|
|
||||||
|
|
||||||
public final static Map<Integer, Piece> initialBoard = Map.ofEntries(
|
|
||||||
// Inspired by Checkers notation rules: https://www.bobnewell.net/nucleus/checkers.php
|
// Inspired by Checkers notation rules: https://www.bobnewell.net/nucleus/checkers.php
|
||||||
Map.entry( 1, BLACK_MAN),
|
Map.entry( 1, Stone.BLACK_MAN),
|
||||||
Map.entry( 2, BLACK_MAN),
|
Map.entry( 2, Stone.BLACK_MAN),
|
||||||
Map.entry( 3, BLACK_MAN),
|
Map.entry( 3, Stone.BLACK_MAN),
|
||||||
Map.entry( 4, BLACK_MAN),
|
Map.entry( 4, Stone.BLACK_MAN),
|
||||||
Map.entry( 5, BLACK_MAN),
|
Map.entry( 5, Stone.BLACK_MAN),
|
||||||
Map.entry( 6, BLACK_MAN),
|
Map.entry( 6, Stone.BLACK_MAN),
|
||||||
Map.entry( 7, BLACK_MAN),
|
Map.entry( 7, Stone.BLACK_MAN),
|
||||||
Map.entry( 8, BLACK_MAN),
|
Map.entry( 8, Stone.BLACK_MAN),
|
||||||
Map.entry( 9, BLACK_MAN),
|
Map.entry( 9, Stone.BLACK_MAN),
|
||||||
Map.entry(10, BLACK_MAN),
|
Map.entry(10, Stone.BLACK_MAN),
|
||||||
Map.entry(11, BLACK_MAN),
|
Map.entry(11, Stone.BLACK_MAN),
|
||||||
Map.entry(12, BLACK_MAN),
|
Map.entry(12, Stone.BLACK_MAN),
|
||||||
|
|
||||||
Map.entry(21, WHITE_MAN),
|
Map.entry(21, Stone.WHITE_MAN),
|
||||||
Map.entry(22, WHITE_MAN),
|
Map.entry(22, Stone.WHITE_MAN),
|
||||||
Map.entry(23, WHITE_MAN),
|
Map.entry(23, Stone.WHITE_MAN),
|
||||||
Map.entry(24, WHITE_MAN),
|
Map.entry(24, Stone.WHITE_MAN),
|
||||||
Map.entry(25, WHITE_MAN),
|
Map.entry(25, Stone.WHITE_MAN),
|
||||||
Map.entry(26, WHITE_MAN),
|
Map.entry(26, Stone.WHITE_MAN),
|
||||||
Map.entry(27, WHITE_MAN),
|
Map.entry(27, Stone.WHITE_MAN),
|
||||||
Map.entry(28, WHITE_MAN),
|
Map.entry(28, Stone.WHITE_MAN),
|
||||||
Map.entry(29, WHITE_MAN),
|
Map.entry(29, Stone.WHITE_MAN),
|
||||||
Map.entry(30, WHITE_MAN),
|
Map.entry(30, Stone.WHITE_MAN),
|
||||||
Map.entry(31, WHITE_MAN),
|
Map.entry(31, Stone.WHITE_MAN),
|
||||||
Map.entry(32, WHITE_MAN)
|
Map.entry(32, Stone.WHITE_MAN)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,23 +8,23 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import djmil.cordacheckers.contracts.GameBoardContract;
|
import djmil.cordacheckers.contracts.GameBoardContract;
|
||||||
import djmil.cordacheckers.contracts.GameBoardContract.MoveResult;
|
import djmil.cordacheckers.contracts.GameBoardContract.MoveResult;
|
||||||
import djmil.cordacheckers.states.Piece.Color;
|
import djmil.cordacheckers.states.Stone.Color;
|
||||||
import net.corda.v5.base.annotations.ConstructorForDeserialization;
|
import net.corda.v5.base.annotations.ConstructorForDeserialization;
|
||||||
import net.corda.v5.base.types.MemberX500Name;
|
import net.corda.v5.base.types.MemberX500Name;
|
||||||
import net.corda.v5.ledger.utxo.BelongsToContract;
|
import net.corda.v5.ledger.utxo.BelongsToContract;
|
||||||
|
|
||||||
@BelongsToContract(GameBoardContract.class)
|
@BelongsToContract(GameBoardContract.class)
|
||||||
public class GameBoardState extends GameState {
|
public class GameBoardState extends GameState {
|
||||||
private final Piece.Color moveColor;
|
private final Stone.Color moveColor;
|
||||||
private final Integer moveNumber;
|
private final Integer moveNumber;
|
||||||
private final Map<Integer, Piece> board;
|
private final Map<Integer, Stone> board;
|
||||||
|
|
||||||
public GameBoardState(GameProposalState gameProposalState) {
|
public GameBoardState(GameProposalState gameProposalState) {
|
||||||
super(gameProposalState.whitePlayer, gameProposalState.blackPlayer,
|
super(gameProposalState.whitePlayer, gameProposalState.blackPlayer,
|
||||||
gameProposalState.gameUuid, gameProposalState.message, gameProposalState.participants);
|
gameProposalState.gameUuid, gameProposalState.message, gameProposalState.participants);
|
||||||
|
|
||||||
this.board = new LinkedHashMap<Integer, Piece>(GameBoardContract.initialBoard);
|
this.board = new LinkedHashMap<Integer, Stone>(GameBoardContract.initialBoard);
|
||||||
this.moveColor = Piece.Color.WHITE;
|
this.moveColor = Stone.Color.WHITE;
|
||||||
this.moveNumber = 0;
|
this.moveNumber = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ public class GameBoardState extends GameState {
|
|||||||
|
|
||||||
@ConstructorForDeserialization
|
@ConstructorForDeserialization
|
||||||
public GameBoardState(MemberX500Name whitePlayer, MemberX500Name blackPlayer,
|
public GameBoardState(MemberX500Name whitePlayer, MemberX500Name blackPlayer,
|
||||||
Color moveColor, Integer moveNumber, Map<Integer, Piece> board, String message,
|
Color moveColor, Integer moveNumber, Map<Integer, Stone> board, String message,
|
||||||
UUID gameUuid, List<PublicKey> participants) {
|
UUID gameUuid, List<PublicKey> participants) {
|
||||||
super(whitePlayer, blackPlayer, gameUuid, message, participants);
|
super(whitePlayer, blackPlayer, gameUuid, message, participants);
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ public class GameBoardState extends GameState {
|
|||||||
this.board = board;
|
this.board = board;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Piece.Color getMoveColor() {
|
public Stone.Color getMoveColor() {
|
||||||
return moveColor;
|
return moveColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,10 +61,10 @@ public class GameBoardState extends GameState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MemberX500Name getActivePlayerName() {
|
public MemberX500Name getActivePlayerName() {
|
||||||
return moveColor == Piece.Color.WHITE ? whitePlayer : blackPlayer;
|
return moveColor == Stone.Color.WHITE ? whitePlayer : blackPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer, Piece> getBoard() {
|
public Map<Integer, Stone> getBoard() {
|
||||||
return board;
|
return board;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,11 +67,11 @@ public abstract class GameState implements ContractState {
|
|||||||
throw new NotInvolved(playerName, this.getClass(), gameUuid);
|
throw new NotInvolved(playerName, this.getClass(), gameUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Piece.Color getOpponentColor(MemberX500Name playerName) throws NotInvolved {
|
public Stone.Color getOpponentColor(MemberX500Name playerName) throws NotInvolved {
|
||||||
if (playerName.compareTo(whitePlayer) == 0)
|
if (playerName.compareTo(whitePlayer) == 0)
|
||||||
return Piece.Color.BLACK;
|
return Stone.Color.BLACK;
|
||||||
if (playerName.compareTo(blackPlayer) == 0)
|
if (playerName.compareTo(blackPlayer) == 0)
|
||||||
return Piece.Color.WHITE;
|
return Stone.Color.WHITE;
|
||||||
throw new NotInvolved(playerName, this.getClass(), gameUuid);
|
throw new NotInvolved(playerName, this.getClass(), gameUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import net.corda.v5.base.annotations.ConstructorForDeserialization;
|
|||||||
import net.corda.v5.base.annotations.CordaSerializable;
|
import net.corda.v5.base.annotations.CordaSerializable;
|
||||||
|
|
||||||
@CordaSerializable
|
@CordaSerializable
|
||||||
public class Piece {
|
public class Stone {
|
||||||
|
|
||||||
@CordaSerializable
|
@CordaSerializable
|
||||||
public enum Type {
|
public enum Type {
|
||||||
@ -31,8 +31,13 @@ public class Piece {
|
|||||||
private final Color color;
|
private final Color color;
|
||||||
private final Type type;
|
private final Type type;
|
||||||
|
|
||||||
|
public final static Stone WHITE_MAN = new Stone(Stone.Color.WHITE, Stone.Type.MAN);
|
||||||
|
public final static Stone WHITE_KING = new Stone(Stone.Color.WHITE, Stone.Type.KING);
|
||||||
|
public final static Stone BLACK_MAN = new Stone(Stone.Color.BLACK, Stone.Type.MAN);
|
||||||
|
public final static Stone BLACK_KING = new Stone(Stone.Color.BLACK, Stone.Type.KING);
|
||||||
|
|
||||||
@ConstructorForDeserialization
|
@ConstructorForDeserialization
|
||||||
public Piece(Color color, Type type) {
|
public Stone(Color color, Type type) {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
@ -53,7 +58,7 @@ public class Piece {
|
|||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
Piece other = (Piece) obj;
|
Stone other = (Stone) obj;
|
||||||
if (color != other.color)
|
if (color != other.color)
|
||||||
return false;
|
return false;
|
||||||
if (type != other.type)
|
if (type != other.type)
|
@ -16,7 +16,7 @@ import djmil.cordacheckers.gamestate.FlowResponce;
|
|||||||
import djmil.cordacheckers.gamestate.View;
|
import djmil.cordacheckers.gamestate.View;
|
||||||
import djmil.cordacheckers.gamestate.ViewBuilder;
|
import djmil.cordacheckers.gamestate.ViewBuilder;
|
||||||
import djmil.cordacheckers.states.GameProposalState;
|
import djmil.cordacheckers.states.GameProposalState;
|
||||||
import djmil.cordacheckers.states.Piece;
|
import djmil.cordacheckers.states.Stone;
|
||||||
import net.corda.v5.application.flows.ClientRequestBody;
|
import net.corda.v5.application.flows.ClientRequestBody;
|
||||||
import net.corda.v5.application.flows.ClientStartableFlow;
|
import net.corda.v5.application.flows.ClientStartableFlow;
|
||||||
import net.corda.v5.application.flows.CordaInject;
|
import net.corda.v5.application.flows.CordaInject;
|
||||||
@ -88,10 +88,10 @@ public class CreateFlow implements ClientStartableFlow{
|
|||||||
private GameProposalState buildGameProposalStateFrom(ClientRequestBody requestBody) {
|
private GameProposalState buildGameProposalStateFrom(ClientRequestBody requestBody) {
|
||||||
final CreateFlowArgs args = requestBody.getRequestBodyAs(jsonMarshallingService, CreateFlowArgs.class);
|
final CreateFlowArgs args = requestBody.getRequestBodyAs(jsonMarshallingService, CreateFlowArgs.class);
|
||||||
|
|
||||||
final Piece.Color opponentColor = Piece.Color.valueOf(args.opponentColor);
|
final Stone.Color opponentColor = Stone.Color.valueOf(args.opponentColor);
|
||||||
if (opponentColor == null) {
|
if (opponentColor == null) {
|
||||||
throw new RuntimeException("Allowed values for opponentColor are: "
|
throw new RuntimeException("Allowed values for opponentColor are: "
|
||||||
+ Piece.Color.WHITE.name() +", " + Piece.Color.BLACK.name()
|
+ Stone.Color.WHITE.name() +", " + Stone.Color.BLACK.name()
|
||||||
+ ". Actual value was: " + args.opponentColor);
|
+ ". Actual value was: " + args.opponentColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,8 +101,8 @@ public class CreateFlow implements ClientStartableFlow{
|
|||||||
"MemberLookup can't find opponentName specified in flow arguments: " + args.opponentName
|
"MemberLookup can't find opponentName specified in flow arguments: " + args.opponentName
|
||||||
);
|
);
|
||||||
|
|
||||||
final MemberInfo whitePlayerInfo = opponentColor == Piece.Color.WHITE ? opponentInfo : myInfo;
|
final MemberInfo whitePlayerInfo = opponentColor == Stone.Color.WHITE ? opponentInfo : myInfo;
|
||||||
final MemberInfo blackPlayerInfo = opponentColor == Piece.Color.BLACK ? opponentInfo : myInfo;
|
final MemberInfo blackPlayerInfo = opponentColor == Stone.Color.BLACK ? opponentInfo : myInfo;
|
||||||
|
|
||||||
return new GameProposalState(
|
return new GameProposalState(
|
||||||
whitePlayerInfo.getName(),
|
whitePlayerInfo.getName(),
|
||||||
|
@ -7,7 +7,7 @@ import java.util.UUID;
|
|||||||
import djmil.cordacheckers.states.GameBoardState;
|
import djmil.cordacheckers.states.GameBoardState;
|
||||||
import djmil.cordacheckers.states.GameProposalState;
|
import djmil.cordacheckers.states.GameProposalState;
|
||||||
import djmil.cordacheckers.states.GameResultState;
|
import djmil.cordacheckers.states.GameResultState;
|
||||||
import djmil.cordacheckers.states.Piece;
|
import djmil.cordacheckers.states.Stone;
|
||||||
import net.corda.v5.base.types.MemberX500Name;
|
import net.corda.v5.base.types.MemberX500Name;
|
||||||
|
|
||||||
// GameBoard from the player's point of view
|
// GameBoard from the player's point of view
|
||||||
@ -27,9 +27,9 @@ public class View {
|
|||||||
public final Status status;
|
public final Status status;
|
||||||
|
|
||||||
public final String opponentName;
|
public final String opponentName;
|
||||||
public final Piece.Color opponentColor;
|
public final Stone.Color opponentColor;
|
||||||
|
|
||||||
public final Map<Integer, Piece> board;
|
public final Map<Integer, Stone> board;
|
||||||
public final Integer moveNumber;
|
public final Integer moveNumber;
|
||||||
public final List<Integer> previousMove;
|
public final List<Integer> previousMove;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user