Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
.idea
*.iws
*.iml
*.ipr
Expand Down
27 changes: 20 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,23 @@
<artifactId>javafx-fxml</artifactId>
<version>17.0.1</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>2.3-groovy-3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>3.0.11</version>
<type>pom</type>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -49,6 +55,13 @@
<configuration>
<source>17</source>
<target>17</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/magbeth/core/Piece.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package magbeth.core;

import javafx.scene.image.Image;
import lombok.EqualsAndHashCode;

import java.util.Objects;

@EqualsAndHashCode
public class Piece {
public enum Color {
BLACK,
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/magbeth/core/moves/Move.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package magbeth.core.moves;

import lombok.EqualsAndHashCode;
import magbeth.core.Board;
import magbeth.core.IGameState;
import magbeth.core.Piece;
import magbeth.core.Vec2;

@EqualsAndHashCode
public class Move {
public Piece piece;
public Vec2 tile;
Expand All @@ -18,6 +20,12 @@ public Move(Vec2 move) {
this.move = move;
}

public Move(Piece piece, Vec2 tile, Vec2 move) {
this.piece = piece;
this.tile = tile;
this.move = move;
}

public Vec2 getFinalTile() {
return this.piece.move(tile, move);
}
Expand All @@ -40,6 +48,6 @@ public Move copy() {

@Override
public String toString() {
return piece + " " + tile + " " + getFinalTile();
return piece + " " + tile + " " + move + " finalTile: " + getFinalTile();
}
}
2 changes: 1 addition & 1 deletion src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module magbeth.magbeth {
requires javafx.controls;
requires javafx.fxml;

requires static lombok;

opens magbeth to javafx.fxml;
exports magbeth;
Expand Down
22 changes: 22 additions & 0 deletions src/test/groovy/magbeth/core/BasicGameStateTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package magbeth.core

import magbeth.core.moves.Move
import spock.lang.Specification

class BasicGameStateTest extends Specification {

def "should return two available moves for white pawn on a2"() {
given:
def board = Board.basicConfig()
def underTest = new BasicGameState(board)
def pawn = new Vec2(6, 0)

when:
def result = underTest.getAvailableMoves(pawn, Piece.Color.WHITE)

then:
result.size() == 2
result == [new Move(new Piece(PieceType.PAWN, Piece.Color.WHITE), pawn, new Vec2(1, 0)),
new Move(new Piece(PieceType.PAWN, Piece.Color.WHITE), pawn, new Vec2(2, 0))]
}
}