Skip to content
Merged
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
1 change: 1 addition & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ tasks {
dependsOn(doc)
dependOnSubprojects()
group = mainGroup
description = "Zips everything up for release into build/deploy"
description = "Zips everything up for release into ./build/deploy"
}

val release by creating {
Expand All @@ -73,7 +73,7 @@ tasks {
println("""
===================================================
Fertig! Jetzt noch folgende Schritte ausfuehren:
- einen Release für die GUI erstellen
- ein Release für die GUI erstellen
- auf der Website (http://www.software-challenge.de/wp-admin) unter Medien die Dateien ersetzen
- unter Seiten die Downloadseite aktualisieren (neue Version in Versionshistorie eintragen)

Expand Down
103 changes: 0 additions & 103 deletions plugin/src/shared/sc/plugin2019/Board.java

This file was deleted.

86 changes: 86 additions & 0 deletions plugin/src/shared/sc/plugin2019/Board.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package sc.plugin2019

import com.thoughtworks.xstream.annotations.XStreamAlias
import com.thoughtworks.xstream.annotations.XStreamImplicit
import sc.api.plugins.IBoard
import sc.plugin2019.FieldState.OBSTRUCTED
import sc.plugin2019.util.Constants
import sc.shared.PlayerColor
import java.util.*

/** Spielbrett für Piranhas mit [Constants.BOARD_SIZE]² Feldern. */
@XStreamAlias(value = "board")
class Board : IBoard {

@XStreamImplicit(itemFieldName = "fields")
private var fields: Array<Array<Field>>

constructor() {
this.fields = randomFields()
}

constructor(boardToClone: Board) {
this.fields = generateFields { x, y -> boardToClone.fields[x][y].clone() }
}

public override fun clone(): Board = Board(this)

override fun equals(other: Any?): Boolean = other is Board && Arrays.equals(other.fields, this.fields)

private fun generateFields(generator: (Int, Int) -> Field): Array<Array<Field>> {
return Array(Constants.BOARD_SIZE) { x ->
Array(Constants.BOARD_SIZE) { y ->
generator(x, y)
}
}
}

/** Erstellt eine zufälliges Spielbrett. */
private fun randomFields(): Array<Array<Field>> {
val fields = generateFields { x, y -> Field(x, y) }

// Place Piranhas
for(index in 1 until Constants.BOARD_SIZE - 1) {
fields[0][index].setPiranha(PlayerColor.RED)
fields[Constants.BOARD_SIZE - 1][index].setPiranha(PlayerColor.RED)
fields[index][0].setPiranha(PlayerColor.BLUE)
fields[index][Constants.BOARD_SIZE - 1].setPiranha(PlayerColor.BLUE)
}

// Place Obstacles
// only consider fields in the middle of the board
var blockableFields: List<Field> = fields.slice(Constants.OBSTACLES_START..Constants.OBSTACLES_END).flatMap { it.slice(Constants.OBSTACLES_START..Constants.OBSTACLES_END) }
// set fields with randomly selected coordinates to blocked
// coordinates may not lay on same horizontal, vertical or diagonal lines with other selected coordinates
for(i in 0 until Constants.NUM_OBSTACLES) {
val indexOfFieldToBlock = Math.floor(Math.random() * blockableFields.size).toInt()
val selectedField = blockableFields[indexOfFieldToBlock]
selectedField.state = OBSTRUCTED
blockableFields = blockableFields.filter { field ->
!(field.x == selectedField.x || field.y == selectedField.y ||
field.x - field.y == selectedField.x - selectedField.y ||
field.x + field.y == selectedField.x + selectedField.y)
}
}
return fields
}

override fun toString() =
"Board " + fields.joinToString(" ", "[", "]") { column -> column.joinToString(", ", prefix = "[", postfix = "]") { it.toString() } }

val line = "-".repeat(Constants.BOARD_SIZE + 2)
fun prettyString(): String {
val map = Array(Constants.BOARD_SIZE) { StringBuilder("|") }
fields.forEach {
it.forEachIndexed { index, field ->
map[index].append(field.state.asLetter())
}
}
return map.joinToString("\n", line + "\n", "\n" + line) { it.append('|').toString() }
}

override fun getField(x: Int, y: Int): Field =
this.fields[x][y]

}

8 changes: 2 additions & 6 deletions plugin/src/shared/sc/plugin2019/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import static sc.plugin2019.FieldState.*;

/**
* Ein Feld des Spielfelds. Ein Spielfeld hat eine x- und y-Koordinate und einen {@link FieldState}.
* Ein Feld des Spielfelds. Ein Spielfeld hat eine x- und y-Koordinate und einen {@link FieldState}, der anzeigt ob sich etwas auf diesem Feld befindet.
*/
@XStreamAlias(value = "field")
public class Field implements IField {
Expand Down Expand Up @@ -89,11 +89,7 @@ else if(state == BLUE)
return Optional.empty();
}

/**
* Nur für den Server (für Test) relevant.
*
* @param piranha Farbe des Piranhas
*/
/** Nur für den Server relevant. */
public void setPiranha(PlayerColor piranha) {
state = FieldState.from(piranha);
}
Expand Down
19 changes: 0 additions & 19 deletions plugin/src/shared/sc/plugin2019/FieldState.java

This file was deleted.

34 changes: 34 additions & 0 deletions plugin/src/shared/sc/plugin2019/FieldState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package sc.plugin2019

import sc.shared.PlayerColor

enum class FieldState {
RED,
BLUE,
OBSTRUCTED,
EMPTY;

override fun toString() = when(this) {
OBSTRUCTED -> "Obstructed"
RED -> "Red"
BLUE -> "Blue"
else -> "empty"
}

fun asLetter() = when(this) {
OBSTRUCTED -> 'O'
RED -> 'R'
BLUE -> 'B'
else -> ' '
}

companion object {
@JvmStatic
fun from(color: PlayerColor): FieldState {
return when(color) {
PlayerColor.RED -> RED
PlayerColor.BLUE -> BLUE
}
}
}
}
8 changes: 5 additions & 3 deletions plugin/src/shared/sc/plugin2019/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ public class Constants {
public static final int GAME_STATS_SWARM_SIZE = 0;
public static final int GAME_STATS_RED_INDEX = 0;
public static final int GAME_STATS_BLUE_INDEX = 1;
public static final int WIN_SCORE = 2;
public static final int LOSE_SCORE = 0;
public static final int DRAW_SCORE = 1;
public static final int WIN_SCORE = 2;

public static final int BOARD_SIZE = 10;
public static final int NUM_OBSTACLES = 2;
public static final int MAX_FISH = (BOARD_SIZE - 2) * 2;
public static final int OBSTACLES_START = 2; // refers to the lowest index at which a obstructed field might be placed
public static final int OBSTACLES_END = 7; // refers to the highest index at which a obstructed field might be placed
/** The lowest index at which a obstructed field may be placed */
public static final int OBSTACLES_START = 2;
/** The highest index at which a obstructed field may be placed */
public static final int OBSTACLES_END = 7;
}
Loading