Skip to content

Commit

Permalink
Heart really is a fantastic band.
Browse files Browse the repository at this point in the history
  • Loading branch information
cheezballs committed Dec 7, 2023
1 parent aa80368 commit 3bb6c9f
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 55 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

# 4 space indentation
[*.{java,xml,json}]
indent_style = tab
indent_size = 2

# Max 120 chars per line
[*.{java,xml,json}]
max_line_length = 140
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package dev.indoors.ringrats.service;

import dev.indoors.ringrats.simulation.match.MatchConfiguration;
import dev.indoors.ringrats.simulation.match.MatchResults;

public interface SimulationService {

void simulateMatch(MatchConfiguration matchConfig);
MatchResults simulateMatch(MatchConfiguration matchConfig);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,24 @@
import dev.indoors.ringrats.service.SimulationService;
import dev.indoors.ringrats.simulation.match.Match;
import dev.indoors.ringrats.simulation.match.MatchConfiguration;
import dev.indoors.ringrats.simulation.match.MatchResults;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class SimulationServiceImpl implements SimulationService {

boolean active;
Match match;
@Override
public MatchResults simulateMatch(MatchConfiguration matchConfig) {
log.debug("Setting up simulation.");
Match match = new Match(matchConfig.getWrestlers(), matchConfig.getStipulations());

@Override
public void simulateMatch(MatchConfiguration matchConfig) {
setupMatch(matchConfig);
match.start();
while (match.isMatchActive()) {
match.simulateTurn();
}

while (active) {
match.simulateTurn();
}

finalizeMatch();
}

private void finalizeMatch() {
}

private void setupMatch(MatchConfiguration matchConfig) {
log.debug("Setting up simulation.");

match = new Match(matchConfig.getWrestlers(), matchConfig.getStipulations());
match.start();
active = true;
}
return match.end();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Match {
Set<Wrestler> wrestlers;
Set<Stipulation> stipulations;
int turnNumber = 0;
boolean matchActive;

public Match(Set<Wrestler> wrestlers, Set<Stipulation> stipulations) {
this.wrestlers = wrestlers;
Expand All @@ -27,6 +28,10 @@ public Match(Set<Wrestler> wrestlers, Set<Stipulation> stipulations) {
public void simulateTurn() {
turnNumber++;
log.debug("Simulating turn {}.", turnNumber);

if (turnNumber > 20) {
matchActive = false;
}
}

public void start() {
Expand All @@ -35,6 +40,7 @@ public void start() {
startingConditions.addAll(wrestler.getStartingConditions());
wrestler.setConditions(startingConditions);
}
matchActive = true;
}

private Set<Condition> getStartingConditions() {
Expand All @@ -45,4 +51,7 @@ private Set<Condition> getStartingConditions() {
return startingConditions;
}

public MatchResults end() {
return new MatchResults();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import dev.indoors.ringrats.simulation.stipulation.Stipulation;
import dev.indoors.ringrats.simulation.wrestler.Wrestler;
import lombok.Getter;
import lombok.Setter;

import java.util.Set;

@Getter
@Setter
public class MatchConfiguration {

@JsonProperty()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.indoors.ringrats.simulation.match;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

@Getter
@Setter
@Slf4j
public class MatchResults {
}
28 changes: 14 additions & 14 deletions src/main/resources/examples/1v1-basic.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"wrestlers": [
{
"name": "Chudd"
},
{
"name": "Rufus"
}
],
"stipulations": [
{
"name": "OneFall"
}
]
}
"wrestlers": [
{
"name": "Chudd"
},
{
"name": "Rufus"
}
],
"stipulations": [
{
"name": "OneFall"
}
]
}
2 changes: 1 addition & 1 deletion src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</encoder>
</appender>

<root level="debug">
<root level="DEBUG">
<appender-ref ref="Console"/>
<appender-ref ref="File"/>
</root>
Expand Down
17 changes: 0 additions & 17 deletions src/test/java/dev/indoors/ringrats/RingRatsTests.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dev.indoors.ringrats.service;

import dev.indoors.ringrats.service.impl.SimulationServiceImpl;
import dev.indoors.ringrats.simulation.match.MatchResults;
import dev.indoors.ringrats.util.MockMatchConfigurations;
import dev.indoors.ringrats.util.MockWrestlers;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.springframework.boot.test.context.SpringBootTest;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest
public class SimulationServiceTests {

@InjectMocks
SimulationServiceImpl simService;

@Test
void firstTest() {
MatchResults results = simService.simulateMatch(MockMatchConfigurations.basicOneFall(MockWrestlers.create("Wang Chung", "Dangerous Davey")));
assertThat(results).isNotNull();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.indoors.ringrats.util;

import dev.indoors.ringrats.simulation.match.MatchConfiguration;
import dev.indoors.ringrats.simulation.stipulation.OneFallStipulation;
import dev.indoors.ringrats.simulation.wrestler.Wrestler;

import java.util.Collections;
import java.util.Set;

public final class MockMatchConfigurations {

private MockMatchConfigurations() {
throw new UnsupportedOperationException("Utility class not intended for instantiation.");
}

public static MatchConfiguration basicOneFall(Set<Wrestler> wrestlers) {
MatchConfiguration configuration = new MatchConfiguration();
configuration.setStipulations(Collections.singleton(new OneFallStipulation()));
configuration.setWrestlers(wrestlers);
return configuration;
}
}
28 changes: 28 additions & 0 deletions src/test/java/dev/indoors/ringrats/util/MockWrestlers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.indoors.ringrats.util;

import dev.indoors.ringrats.simulation.wrestler.Wrestler;

import java.util.HashSet;
import java.util.Set;

public final class MockWrestlers {

private MockWrestlers() {
throw new UnsupportedOperationException("Utility class not intended for instantiation.");
}

public static Wrestler create(String name) {
Wrestler wrestler = new Wrestler();
wrestler.setName(name);
return wrestler;
}

public static Set<Wrestler> create(String... names) {
Set<Wrestler> wrestlers = new HashSet<>();
for (String name : names) {
wrestlers.add(create(name));
}
return wrestlers;
}

}
27 changes: 27 additions & 0 deletions src/test/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} - %msg%n</pattern>
</encoder>
</appender>

<appender name="File" class="ch.qos.logback.core.FileAppender">
<file>logs/ring-rats.log</file>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<root level="ERROR">
<appender-ref ref="Console"/>
<appender-ref ref="File"/>
</root>

<!-- Quiet down, you-->
<logger name="org.springframework.context" level="ERROR"/>
<logger name="org.springframework.beans.factory" level="ERROR"/>
<logger name="org.springframework.boot.autoconfigure.logging" level="ERROR"/>

</configuration>

0 comments on commit 3bb6c9f

Please sign in to comment.