Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
tsaglam committed Oct 5, 2023
2 parents eae9992 + de8a3cb commit 04ece25
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 19 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: SonarCloud
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build and analyze
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=tsaglam_Carcassonne
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
<sonar.organization>tsaglam</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>

<dependencies>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/carcassonne/control/ControllerFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import carcassonne.view.GlobalKeyBindingManager;

/**
* Facade for the game controller. Allows to call view classes or potentially external services to make requests regarding
* the game flow.
* Facade for the game controller. Allows to call view classes or potentially external services to make requests
* regarding the game flow.
* @author Timur Saglam
*/
public interface ControllerFacade {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/carcassonne/model/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ public boolean hasEmptyHand() {
* Returns a meeple after its job is down. Allows the player to place another meeple.
*/
public void returnMeeple(Meeple meeple) {
assert placedMeeples.remove(meeple);
boolean isRemoved = placedMeeples.remove(meeple);
assert isRemoved;
freeMeeples++;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/carcassonne/model/Round.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Round {

private static final String NOTHING = "";
private static final String SQUARE_BRACKETS = "[\\[\\]]";

private int activePlayerIndex;
private final Grid grid;
private Player[] players;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/carcassonne/model/ai/RuleBasedComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public int compare(AbstractCarcassonneMove firstMove, AbstractCarcassonneMove se
private int compareMoveType(AbstractCarcassonneMove move) {
if (move.involvesMeeplePlacement()) {
switch (move.getMeepleType()) {
case CASTLE:
return 3;
case MONASTERY:
return 2;
case ROAD:
return 1;
default:
case CASTLE:
return 3;
case MONASTERY:
return 2;
case ROAD:
return 1;
default:
}
}
return 0; // fields or no meeple placed
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/carcassonne/model/grid/GridDirection.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public GridDirection nextDirectionTo(RotationDirection side) {
if (this == CENTER) {
return this;
}
GridDirection[] cycle = { NORTH, NORTH_EAST, EAST, SOUTH_EAST, SOUTH, SOUTH_WEST, WEST, NORTH_WEST };
GridDirection[] cycle = {NORTH, NORTH_EAST, EAST, SOUTH_EAST, SOUTH, SOUTH_WEST, WEST, NORTH_WEST};
int position = -2; // error case, sum with parameter side is negative
for (int i = 0; i < cycle.length; i++) {
if (cycle[i] == this) { // find in cycle
Expand Down Expand Up @@ -167,6 +167,6 @@ public static List<GridDirection> byRow() {
* @return a 2D list of of NORTH_WEST, WEST, SOUTH_WEST, NORTH, CENTER, SOUTH, NORTH_EAST, EAST and SOUTH_EAST.
*/
public static GridDirection[][] values2D() {
return new GridDirection[][] { { NORTH_WEST, WEST, SOUTH_WEST }, { NORTH, CENTER, SOUTH }, { NORTH_EAST, EAST, SOUTH_EAST } };
return new GridDirection[][] {{NORTH_WEST, WEST, SOUTH_WEST}, {NORTH, CENTER, SOUTH}, {NORTH_EAST, EAST, SOUTH_EAST}};
}
}
6 changes: 3 additions & 3 deletions src/main/java/carcassonne/settings/GameSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public class GameSettings {
private static final String MEEPLE_PATH = "meeple/meeple_";
private static final String PNG = ".png";
private static final String TEMPLATE = "_template";
private static final String[] DEFAULT_NAMES = { "ONE", "TWO", "THREE", "FOUR", "FIVE" };
private static final String[] DEFAULT_NAMES = {"ONE", "TWO", "THREE", "FOUR", "FIVE"};

// COLOR CONSTANTS:
public static final Color UI_COLOR = new Color(190, 190, 190);
private static final PlayerColor[] DEFAULT_COLORS = { new PlayerColor(30, 26, 197), new PlayerColor(151, 4, 12), new PlayerColor(14, 119, 25),
new PlayerColor(216, 124, 0), new PlayerColor(96, 0, 147) };
private static final PlayerColor[] DEFAULT_COLORS = {new PlayerColor(30, 26, 197), new PlayerColor(151, 4, 12), new PlayerColor(14, 119, 25),
new PlayerColor(216, 124, 0), new PlayerColor(96, 0, 147)};

// COSMETIC:
private final List<PlayerColor> colors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class GameStatisticsModel extends AbstractTableModel {

private static final long serialVersionUID = -7138458001360243937L; // generated UID
private final Round round;
private static final String[] HEADER = { "Player", "Castle", "Road", "Monastery", "Field", "SCORE" };
private static final String[] HEADER = {"Player", "Castle", "Road", "Monastery", "Field", "SCORE"};

/**
* Creates the game statistics model with the current round.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.ToolTipManager;

import carcassonne.model.terrain.TerrainType;
import carcassonne.model.tile.TileDistribution;
Expand Down Expand Up @@ -195,7 +194,7 @@ private JPanel createFortificationPanel() {
panel.add(checkBox);
return panel;
}

private JPanel createEnclavePanel() {
JPanel panel = createBasicPanel(ENCLAVE);
panel.setToolTipText(ENCLAVE_TOOL_TIP);
Expand Down

0 comments on commit 04ece25

Please sign in to comment.