Merge commit '45bfbeca7c1b748a9997877d715c128f99e3a63f' as 'solution/H01'
This commit is contained in:
commit
a52319662a
37 changed files with 2272 additions and 0 deletions
12
solution/H01/.editorconfig
Normal file
12
solution/H01/.editorconfig
Normal file
|
@ -0,0 +1,12 @@
|
|||
# Editor configuration, see https://editorconfig.org
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[{*.yml,*.json}]
|
||||
indent_size = 2
|
86
solution/H01/.gitignore
vendored
Normal file
86
solution/H01/.gitignore
vendored
Normal file
|
@ -0,0 +1,86 @@
|
|||
### Intellij ###
|
||||
.idea/
|
||||
*.iws
|
||||
/out/
|
||||
*.iml
|
||||
.idea_modules/
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
### VS-Code ###
|
||||
.vscode/
|
||||
.VSCodeCounter/
|
||||
|
||||
### Eclipse ###
|
||||
.metadata
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
.recommenders
|
||||
.externalToolBuilders/
|
||||
*.launch
|
||||
.factorypath
|
||||
.recommenders/
|
||||
.apt_generated/
|
||||
.project
|
||||
.classpath
|
||||
|
||||
### Linux ###
|
||||
*~
|
||||
.fuse_hidden*
|
||||
.directory
|
||||
.Trash-*
|
||||
.nfs*
|
||||
|
||||
### macOS ###
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
Icon
|
||||
._*
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### NetBeans ###
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
.nb-gradle/
|
||||
|
||||
### Windows ###
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
*.stackdump
|
||||
[Dd]esktop.ini
|
||||
$RECYCLE.BIN/
|
||||
*.lnk
|
||||
|
||||
### Gradle ###
|
||||
.gradle
|
||||
/build/
|
||||
out/
|
||||
gradle-app.setting
|
||||
!gradle-wrapper.jar
|
||||
.gradletasknamecache
|
||||
|
||||
*.hprof
|
||||
jagr.conf
|
4
solution/H01/README.md
Normal file
4
solution/H01/README.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
# Musterlösung zu Hausübung 01
|
||||
|
||||
Beachten Sie die Hinweise zum Herunterladen, Importieren, Bearbeitern, Exportieren und Hochladen in unserem
|
||||
[Studierenden-Guide](https://wiki.tudalgo.org/)
|
41
solution/H01/build.gradle.kts
Normal file
41
solution/H01/build.gradle.kts
Normal file
|
@ -0,0 +1,41 @@
|
|||
plugins {
|
||||
alias(libs.plugins.algomate)
|
||||
alias(libs.plugins.style)
|
||||
}
|
||||
|
||||
version = file("version").readLines().first()
|
||||
|
||||
exercise {
|
||||
assignmentId.set("h01")
|
||||
}
|
||||
|
||||
submission {
|
||||
// ACHTUNG!
|
||||
// Setzen Sie im folgenden Bereich Ihre TU-ID (NICHT Ihre Matrikelnummer!), Ihren Nachnamen und Ihren Vornamen
|
||||
// in Anführungszeichen (z.B. "ab12cdef" für Ihre TU-ID) ein!
|
||||
// BEISPIEL:
|
||||
// studentId = "ab12cdef"
|
||||
// firstName = "sol_first"
|
||||
// lastName = "sol_last"
|
||||
studentId = "ab12cdef"
|
||||
firstName = "sol_first"
|
||||
lastName = "sol_last"
|
||||
|
||||
// Optionally require own tests for mainBuildSubmission task. Default is false
|
||||
requireTests = false
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.fopbot)
|
||||
}
|
||||
|
||||
jagr {
|
||||
graders {
|
||||
val graderPublic by getting
|
||||
val graderPrivate by creating {
|
||||
parent(graderPublic)
|
||||
graderName.set("FOP-2425-H01-Private")
|
||||
rubricProviderName.set("h01.H01_RubricProvider")
|
||||
}
|
||||
}
|
||||
}
|
6
solution/H01/gradle/libs.versions.toml
Normal file
6
solution/H01/gradle/libs.versions.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
[plugins]
|
||||
algomate = { id = "org.tudalgo.algomate", version = "0.7.1" }
|
||||
style = { id = "org.sourcegrade.style", version = "3.0.0" }
|
||||
|
||||
[libraries]
|
||||
fopbot = { module = "org.tudalgo:fopbot", version = "0.8.1" }
|
BIN
solution/H01/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
solution/H01/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
solution/H01/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
solution/H01/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
|
||||
networkTimeout=10000
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
245
solution/H01/gradlew
vendored
Executable file
245
solution/H01/gradlew
vendored
Executable file
|
@ -0,0 +1,245 @@
|
|||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
92
solution/H01/gradlew.bat
vendored
Normal file
92
solution/H01/gradlew.bat
vendored
Normal file
|
@ -0,0 +1,92 @@
|
|||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
11
solution/H01/settings.gradle.kts
Normal file
11
solution/H01/settings.gradle.kts
Normal file
|
@ -0,0 +1,11 @@
|
|||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
// mavenLocal()
|
||||
maven("https://s01.oss.sonatype.org/content/repositories/snapshots")
|
||||
maven("https://jitpack.io")
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "H01-Root"
|
85
solution/H01/src/graderPrivate/java/h01/BlueGhostTest.java
Normal file
85
solution/H01/src/graderPrivate/java/h01/BlueGhostTest.java
Normal file
|
@ -0,0 +1,85 @@
|
|||
package h01;
|
||||
|
||||
import fopbot.Robot;
|
||||
import fopbot.Transition;
|
||||
import fopbot.World;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.sourcegrade.jagr.api.rubric.TestForSubmission;
|
||||
import org.tudalgo.algoutils.tutor.general.assertions.Context;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.tudalgo.algoutils.tutor.general.assertions.Assertions2.*;
|
||||
|
||||
@TestForSubmission
|
||||
public class BlueGhostTest {
|
||||
|
||||
private BlueGhost blueGhost;
|
||||
private Context context;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
int worldHeight = 5;
|
||||
int worldWidth = 5;
|
||||
int startX = 2;
|
||||
int startY = 2;
|
||||
World.setSize(worldWidth, worldHeight);
|
||||
World.setDelay(0);
|
||||
World.placeVerticalWall(startX, startY);
|
||||
World.placeHorizontalWall(startX, startY);
|
||||
blueGhost = new BlueGhost(startX, startY);
|
||||
context = contextBuilder()
|
||||
.add("world width", worldWidth)
|
||||
.add("world height", worldHeight)
|
||||
.add("blue ghost", blueGhost)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRightTurn() {
|
||||
call(blueGhost::doMove, context, result -> "An exception was thrown while invoking doMove");
|
||||
|
||||
List<Transition.RobotAction> expected = List.of(
|
||||
Transition.RobotAction.TURN_LEFT,
|
||||
Transition.RobotAction.TURN_LEFT,
|
||||
Transition.RobotAction.TURN_LEFT
|
||||
);
|
||||
List<Transition.RobotAction> actual = getRobotActions(blueGhost, 0, 3);
|
||||
assertEquals(expected, actual, context, result -> "Blue ghost did not turn right");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLeftTurns() {
|
||||
call(blueGhost::doMove, context, result -> "An exception was thrown while invoking doMove");
|
||||
|
||||
List<Transition.RobotAction> expected = List.of(
|
||||
Transition.RobotAction.TURN_LEFT,
|
||||
Transition.RobotAction.TURN_LEFT
|
||||
);
|
||||
List<Transition.RobotAction> actual = getRobotActions(blueGhost, 3, 5);
|
||||
assertEquals(expected, actual, context, result -> "Blue ghost did not turn left until not facing a wall");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMove() {
|
||||
call(blueGhost::doMove, context, result -> "An exception was thrown while invoking doMove");
|
||||
|
||||
List<Transition.RobotAction> expected = List.of(
|
||||
Transition.RobotAction.MOVE,
|
||||
Transition.RobotAction.NONE
|
||||
);
|
||||
List<Transition.RobotAction> actual = getRobotActions(blueGhost, 5, 7);
|
||||
assertEquals(expected, actual, context, result -> "Blue ghost did not move one step");
|
||||
}
|
||||
|
||||
private static List<Transition.RobotAction> getRobotActions(Robot robot, int from, int to) {
|
||||
return World.getGlobalWorld()
|
||||
.getTrace(robot)
|
||||
.getTransitions()
|
||||
.subList(from, to)
|
||||
.stream()
|
||||
.map(transition -> transition.action)
|
||||
.toList();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package h01;
|
||||
|
||||
import fopbot.Direction;
|
||||
import org.sourcegrade.jagr.api.rubric.*;
|
||||
import static org.tudalgo.algoutils.tutor.general.jagr.RubricUtils.criterion;
|
||||
|
||||
public class H01_RubricProvider implements RubricProvider {
|
||||
|
||||
private static final Criterion H1_1 = Criterion.builder()
|
||||
.shortDescription("H1.1 | Steuerung von Pacman")
|
||||
.maxPoints(4)
|
||||
.addChildCriteria(
|
||||
criterion("Pacman kann sich nach links, rechts, oben und unten bewegen.", 2,
|
||||
JUnitTestRef.ofMethod(() -> PacmanTest.class.getDeclaredMethod("testBasicMovement", Direction.class))),
|
||||
criterion("Pacman kann sich nicht durch Wände bewegen.",
|
||||
JUnitTestRef.ofMethod(() -> PacmanTest.class.getDeclaredMethod("testMovementWithWalls", Direction.class))),
|
||||
criterion("Pacman sammelt Münzen auf, wenn er sich auf ein Feld mit einer Münze bewegt.",
|
||||
JUnitTestRef.ofMethod(() -> PacmanTest.class.getDeclaredMethod("testMovementWithCoins", Direction.class))))
|
||||
.build();
|
||||
|
||||
private static final Criterion H1_2_1 = Criterion.builder()
|
||||
.shortDescription("H1.2.1 | Blaues Gespenst")
|
||||
.maxPoints(2)
|
||||
.addChildCriteria(
|
||||
criterion("Das blaue Gespenst dreht sich nach rechts.",
|
||||
JUnitTestRef.ofMethod(() -> BlueGhostTest.class.getDeclaredMethod("testRightTurn"))),
|
||||
criterion("Wenn eine Wand vor dem blauen Gespenst ist, dreht es sich nach links, bis es keine Wand mehr vor sich hat.",
|
||||
JUnitTestRef.ofMethod(() -> BlueGhostTest.class.getDeclaredMethod("testLeftTurns"))),
|
||||
criterion("Das blaue Gespenst bewegt sich ein Feld nach vorne.",
|
||||
JUnitTestRef.ofMethod(() -> BlueGhostTest.class.getDeclaredMethod("testMove"))))
|
||||
.build();
|
||||
|
||||
private static final Criterion H1_2_2 = Criterion.builder()
|
||||
.shortDescription("H1.2.2 | Pinkes Gespenst")
|
||||
.maxPoints(3)
|
||||
.addChildCriteria(
|
||||
criterion("Das pinke Gespenst wählt einen zufälligen Weg aus den freien Wegen.",
|
||||
JUnitTestRef.ofMethod(() -> PinkGhostTest.class.getDeclaredMethod("testPicksRandomFreePath"))),
|
||||
criterion("Das pinke Gespenst dreht sich zu dem gewählten freien Weg.",
|
||||
JUnitTestRef.ofMethod(() -> PinkGhostTest.class.getDeclaredMethod("testTurnToFreePath"))),
|
||||
criterion("Das pinke Gespenst bewegt sich ein Feld nach vorne.",
|
||||
JUnitTestRef.ofMethod(() -> PinkGhostTest.class.getDeclaredMethod("testMove"))))
|
||||
.build();
|
||||
|
||||
private static final Criterion H1_2_3 = Criterion.builder()
|
||||
.shortDescription("H1.2.3 | Oranges Gespenst")
|
||||
.maxPoints(4)
|
||||
.addChildCriteria(
|
||||
criterion("Das orange Gespenst läuft solange nach vorne, bis eine Wand vor ihm ist.",
|
||||
JUnitTestRef.ofMethod(() -> OrangeGhostTest.class.getDeclaredMethod("testMoveForward"))),
|
||||
criterion("Das orange Gespenst dreht sich nach dem ersten Aufruf rechts herum.",
|
||||
JUnitTestRef.ofMethod(() -> OrangeGhostTest.class.getDeclaredMethod("testTurnsRight"))),
|
||||
criterion("Das orange Gespenst kehrt am des Aufrufs von doMove() seine Drehrichtung um.", 2,
|
||||
JUnitTestRef.ofMethod(() -> OrangeGhostTest.class.getDeclaredMethod("testSwitchTurning"))))
|
||||
.build();
|
||||
|
||||
private static final Criterion H1_2_4 = Criterion.builder()
|
||||
.shortDescription("H1.2.4 | Rotes Gespenst")
|
||||
.maxPoints(3)
|
||||
.addChildCriteria(
|
||||
criterion("Das rote Gespenst dreht sich in die Richtung in der sich Pacman befindet.",
|
||||
JUnitTestRef.ofMethod(() -> RedGhostTest.class.getDeclaredMethod("testTurnToPacman"))),
|
||||
criterion("Das rote Gespenst dreht weiter nach links, bis es keine Wand mehr vor sich hat.",
|
||||
JUnitTestRef.ofMethod(() -> RedGhostTest.class.getDeclaredMethod("testTurnLeft"))),
|
||||
criterion("Das rote Gespenst bewegt sich ein Feld nach vorne.",
|
||||
JUnitTestRef.ofMethod(() -> RedGhostTest.class.getDeclaredMethod("testMove"))))
|
||||
.build();
|
||||
|
||||
private static final Criterion H1_2 = Criterion.builder()
|
||||
.shortDescription("H1.2 | Die Gespenster kommen")
|
||||
.addChildCriteria(
|
||||
H1_2_1, H1_2_2, H1_2_3, H1_2_4)
|
||||
.build();
|
||||
|
||||
public static final Rubric RUBRIC = Rubric.builder()
|
||||
.title("H01 | Pacman")
|
||||
.addChildCriteria(
|
||||
H1_1,
|
||||
H1_2)
|
||||
.build();
|
||||
|
||||
@Override
|
||||
public Rubric getRubric() {
|
||||
return RUBRIC;
|
||||
}
|
||||
}
|
88
solution/H01/src/graderPrivate/java/h01/OrangeGhostTest.java
Normal file
88
solution/H01/src/graderPrivate/java/h01/OrangeGhostTest.java
Normal file
|
@ -0,0 +1,88 @@
|
|||
package h01;
|
||||
|
||||
import fopbot.Direction;
|
||||
import fopbot.Robot;
|
||||
import fopbot.Transition;
|
||||
import fopbot.World;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.sourcegrade.jagr.api.rubric.TestForSubmission;
|
||||
import org.tudalgo.algoutils.tutor.general.assertions.Context;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.tudalgo.algoutils.tutor.general.assertions.Assertions2.*;
|
||||
|
||||
@TestForSubmission
|
||||
public class OrangeGhostTest {
|
||||
|
||||
private final int startX = 1;
|
||||
private final int startY = 1;
|
||||
private OrangeGhost orangeGhost;
|
||||
private Context context;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
int worldHeight = 3;
|
||||
int worldWidth = 3;
|
||||
World.setSize(worldWidth, worldHeight);
|
||||
World.setDelay(0);
|
||||
orangeGhost = new OrangeGhost(startX, startY);
|
||||
context = contextBuilder()
|
||||
.add("world height", worldHeight)
|
||||
.add("world width", worldWidth)
|
||||
.add("orange ghost", orangeGhost)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoveForward() {
|
||||
call(orangeGhost::doMove, context, result -> "An exception occurred while invoking doMove"); // move up
|
||||
|
||||
assertEquals(startX, orangeGhost.getX(), context, result -> "Orange ghost's x-coordinate is incorrect");
|
||||
assertEquals(startY + 1, orangeGhost.getY(), context, result -> "Orange ghost's y-coordinate is incorrect");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTurnsRight() {
|
||||
call(orangeGhost::doMove, context, result -> "An exception occurred while invoking doMove"); // move up
|
||||
call(orangeGhost::doMove, context, result -> "An exception occurred while invoking doMove"); // turn right
|
||||
|
||||
assertEquals(Direction.RIGHT, orangeGhost.getDirection(), context, result -> "Orange ghost is not facing right");
|
||||
List<Transition.RobotAction> expected = List.of(
|
||||
Transition.RobotAction.TURN_LEFT,
|
||||
Transition.RobotAction.TURN_LEFT,
|
||||
Transition.RobotAction.TURN_LEFT,
|
||||
Transition.RobotAction.NONE
|
||||
);
|
||||
List<Transition.RobotAction> actual = getRobotActions(orangeGhost, 1, 5);
|
||||
assertEquals(expected, actual, context, result -> "Orange ghost did not perform the expected actions (1x right turn)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwitchTurning() {
|
||||
call(orangeGhost::doMove, context, result -> "An exception occurred while invoking doMove"); // move up
|
||||
call(orangeGhost::doMove, context, result -> "An exception occurred while invoking doMove"); // turn right
|
||||
call(orangeGhost::doMove, context, result -> "An exception occurred while invoking doMove"); // move right
|
||||
call(orangeGhost::doMove, context, result -> "An exception occurred while invoking doMove"); // turn left
|
||||
|
||||
assertEquals(Direction.LEFT, orangeGhost.getDirection(), context, result -> "Orange ghost is not facing left");
|
||||
List<Transition.RobotAction> expected = List.of(
|
||||
Transition.RobotAction.TURN_LEFT,
|
||||
Transition.RobotAction.TURN_LEFT,
|
||||
Transition.RobotAction.NONE
|
||||
);
|
||||
List<Transition.RobotAction> actual = getRobotActions(orangeGhost, 5, 8);
|
||||
assertEquals(expected, actual, context, result -> "Orange ghost did not perform the expected actions (2x left turn)");
|
||||
}
|
||||
|
||||
private static List<Transition.RobotAction> getRobotActions(Robot robot, int from, int to) {
|
||||
return World.getGlobalWorld()
|
||||
.getTrace(robot)
|
||||
.getTransitions()
|
||||
.subList(from, to)
|
||||
.stream()
|
||||
.map(transition -> transition.action)
|
||||
.toList();
|
||||
}
|
||||
}
|
87
solution/H01/src/graderPrivate/java/h01/PacmanTest.java
Normal file
87
solution/H01/src/graderPrivate/java/h01/PacmanTest.java
Normal file
|
@ -0,0 +1,87 @@
|
|||
package h01;
|
||||
|
||||
import fopbot.Coin;
|
||||
import fopbot.Direction;
|
||||
import fopbot.World;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
import org.sourcegrade.jagr.api.rubric.TestForSubmission;
|
||||
import org.tudalgo.algoutils.tutor.general.assertions.Context;
|
||||
|
||||
import static org.tudalgo.algoutils.tutor.general.assertions.Assertions2.*;
|
||||
|
||||
@TestForSubmission
|
||||
public class PacmanTest {
|
||||
|
||||
private final int startX = 2;
|
||||
private final int startY = 2;
|
||||
private Pacman pacman;
|
||||
private Context.Builder<?> baseContext;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
World.setSize(5, 5);
|
||||
World.setDelay(0);
|
||||
pacman = new Pacman(startX, startY);
|
||||
baseContext = contextBuilder()
|
||||
.add("world height", 5)
|
||||
.add("world width", 5)
|
||||
.add("pacman", pacman);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(Direction.class)
|
||||
public void testBasicMovement(Direction direction) {
|
||||
Context context = baseContext
|
||||
.add("k", direction.ordinal())
|
||||
.build();
|
||||
call(() -> pacman.handleKeyInput(direction.ordinal()), context, result -> "An exception occurred while invoking handleInputKey");
|
||||
|
||||
assertEquals(direction, pacman.getDirection(), context, result ->
|
||||
"Pacman is not facing towards the expected direction");
|
||||
assertEquals(startX + direction.getDx(), pacman.getX(), context, result ->
|
||||
"Pacman's x-coordinate is incorrect");
|
||||
assertEquals(startY + direction.getDy(), pacman.getY(), context, result ->
|
||||
"Pacman's y-coordinate is incorrect");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(Direction.class)
|
||||
public void testMovementWithWalls(Direction direction) {
|
||||
World.placeHorizontalWall(startX, startY - 1);
|
||||
World.placeHorizontalWall(startX, startY);
|
||||
World.placeVerticalWall(startX - 1, startY);
|
||||
World.placeVerticalWall(startX, startY);
|
||||
Context context = baseContext
|
||||
.add("k", direction.ordinal())
|
||||
.build();
|
||||
call(() -> pacman.handleKeyInput(direction.ordinal()), context, result -> "An exception occurred while invoking handleInputKey");
|
||||
|
||||
assertEquals(startX, pacman.getX(), context, result -> "Pacman's x-coordinate is incorrect");
|
||||
assertEquals(startY, pacman.getY(), context, result -> "Pacman's y-coordinate is incorrect");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(Direction.class)
|
||||
public void testMovementWithCoins(Direction direction) {
|
||||
World.putCoins(startX, startY + 1, 1);
|
||||
World.putCoins(startX + 1, startY, 1);
|
||||
World.putCoins(startX, startY - 1, 1);
|
||||
World.putCoins(startX - 1, startY, 1);
|
||||
Context context = baseContext
|
||||
.add("k", direction.ordinal())
|
||||
.build();
|
||||
call(() -> pacman.handleKeyInput(direction.ordinal()), context, result -> "An exception occurred while invoking handleInputKey");
|
||||
|
||||
assertEquals(1, pacman.getNumberOfCoins(), context, result ->
|
||||
"Pacman did not pick up the expected number of coins");
|
||||
boolean pickedUpCorrectCoin = World.getGlobalWorld()
|
||||
.getField(startX + direction.getDx(), startY + direction.getDy())
|
||||
.getEntities()
|
||||
.stream()
|
||||
.noneMatch(fieldEntity -> fieldEntity instanceof Coin);
|
||||
assertTrue(pickedUpCorrectCoin, context, result ->
|
||||
"Pacman did not pick up the coin at (%d, %d)".formatted(startX + direction.getDx(), startY + direction.getDy()));
|
||||
}
|
||||
}
|
107
solution/H01/src/graderPrivate/java/h01/PinkGhostTest.java
Normal file
107
solution/H01/src/graderPrivate/java/h01/PinkGhostTest.java
Normal file
|
@ -0,0 +1,107 @@
|
|||
package h01;
|
||||
|
||||
import static org.tudalgo.algoutils.tutor.general.assertions.Assertions2.assertEquals;
|
||||
import static org.tudalgo.algoutils.tutor.general.assertions.Assertions2.call;
|
||||
import static org.tudalgo.algoutils.tutor.general.assertions.Assertions2.contextBuilder;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.sourcegrade.jagr.api.rubric.TestForSubmission;
|
||||
import org.tudalgo.algoutils.tutor.general.assertions.Context;
|
||||
|
||||
import fopbot.Direction;
|
||||
import fopbot.World;
|
||||
import h01.template.Util;
|
||||
|
||||
@TestForSubmission
|
||||
public class PinkGhostTest {
|
||||
|
||||
private final int startX = 2;
|
||||
private final int startY = 2;
|
||||
private PinkGhost pinkGhost;
|
||||
private Context context;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
int worldHeight = 5;
|
||||
int worldWidth = 5;
|
||||
World.setSize(worldWidth, worldHeight);
|
||||
World.setDelay(0);
|
||||
World.placeHorizontalWall(startX, startY - 1);
|
||||
World.placeHorizontalWall(startX, startY);
|
||||
pinkGhost = new PinkGhost(startX, startY);
|
||||
context = contextBuilder()
|
||||
.add("world height", worldHeight)
|
||||
.add("world width", worldWidth)
|
||||
.add("pink ghost", pinkGhost)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPicksRandomFreePath() throws ReflectiveOperationException {
|
||||
Method getRandomIntegerMethod = Util.class.getDeclaredMethod("getRandomInteger", int.class, int.class);
|
||||
AtomicInteger min = new AtomicInteger(-1);
|
||||
AtomicInteger max = new AtomicInteger(-1);
|
||||
Answer<?> answer = invocation -> {
|
||||
if (invocation.getMethod().equals(getRandomIntegerMethod)) {
|
||||
min.set(invocation.getArgument(0));
|
||||
max.set(invocation.getArgument(1));
|
||||
return 1;
|
||||
} else {
|
||||
return invocation.callRealMethod();
|
||||
}
|
||||
};
|
||||
try (MockedStatic<Util> unused = Mockito.mockStatic(Util.class, answer)) {
|
||||
pinkGhost.doMove();
|
||||
} catch (Exception e) {
|
||||
System.err.println("An exception was thrown but I will attempt to salvage it. Details: " + e.getMessage());
|
||||
}
|
||||
|
||||
assertEquals(1, min.get(), context, result -> "Method doMove did not call getRandomInteger with min = 1");
|
||||
assertEquals(2, max.get(), context, result -> "Method doMove did not call getRandomInteger with max = 2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTurnToFreePath() throws ReflectiveOperationException {
|
||||
Method getRandomIntegerMethod = Util.class.getDeclaredMethod("getRandomInteger", int.class, int.class);
|
||||
Answer<?> answer = invocation -> {
|
||||
if (invocation.getMethod().equals(getRandomIntegerMethod)) {
|
||||
return 2;
|
||||
} else {
|
||||
return invocation.callRealMethod();
|
||||
}
|
||||
};
|
||||
try (MockedStatic<Util> unused = Mockito.mockStatic(Util.class, answer)) {
|
||||
call(pinkGhost::doMove, context, result -> "An exception occurred while invoking doMove");
|
||||
}
|
||||
|
||||
assertEquals(Direction.RIGHT, pinkGhost.getDirection(), context,
|
||||
result -> "Pink ghost does not face the right direction");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMove() throws ReflectiveOperationException {
|
||||
Method getRandomIntegerMethod = Util.class.getDeclaredMethod("getRandomInteger", int.class, int.class);
|
||||
Answer<?> answer = invocation -> {
|
||||
if (invocation.getMethod().equals(getRandomIntegerMethod)) {
|
||||
return 1;
|
||||
} else {
|
||||
return invocation.callRealMethod();
|
||||
}
|
||||
};
|
||||
try (MockedStatic<Util> unused = Mockito.mockStatic(Util.class, answer)) {
|
||||
call(pinkGhost::doMove, context, result -> "An exception occurred while invoking doMove");
|
||||
}
|
||||
|
||||
assertEquals(startX + Direction.LEFT.getDx(), pinkGhost.getX(), context,
|
||||
result -> "The pink ghost's x-coordinate is incorrect");
|
||||
assertEquals(startY + Direction.LEFT.getDy(), pinkGhost.getY(), context,
|
||||
result -> "The pink ghost's y-coordinate is incorrect");
|
||||
}
|
||||
}
|
81
solution/H01/src/graderPrivate/java/h01/RedGhostTest.java
Normal file
81
solution/H01/src/graderPrivate/java/h01/RedGhostTest.java
Normal file
|
@ -0,0 +1,81 @@
|
|||
package h01;
|
||||
|
||||
import fopbot.Direction;
|
||||
import fopbot.Robot;
|
||||
import fopbot.World;
|
||||
import h01.template.Util;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.sourcegrade.jagr.api.rubric.TestForSubmission;
|
||||
import org.tudalgo.algoutils.tutor.general.assertions.Context;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.tudalgo.algoutils.tutor.general.assertions.Assertions2.*;
|
||||
|
||||
@TestForSubmission
|
||||
public class RedGhostTest {
|
||||
|
||||
private final int startX = 1;
|
||||
private final int startY = 1;
|
||||
private Pacman chased;
|
||||
private RedGhost redGhost;
|
||||
private Context context;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
int worldHeight = 3;
|
||||
int worldWidth = 3;
|
||||
World.setSize(worldWidth, worldHeight);
|
||||
World.setDelay(0);
|
||||
World.placeVerticalWall(startX, startY);
|
||||
World.placeHorizontalWall(startX, startY);
|
||||
chased = new Pacman(worldWidth - 1, worldHeight - 1);
|
||||
redGhost = new RedGhost(startX, startY, chased);
|
||||
context = contextBuilder()
|
||||
.add("world height", worldHeight)
|
||||
.add("world width", worldWidth)
|
||||
.add("chased", chased)
|
||||
.add("red ghost", redGhost)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTurnToPacman() throws ReflectiveOperationException {
|
||||
AtomicReference<Robot> chasedRef = new AtomicReference<>();
|
||||
AtomicReference<Robot> chaserRef = new AtomicReference<>();
|
||||
Method furthestDirectionMethod = Util.class.getDeclaredMethod("furthestDirection", Robot.class, Robot.class);
|
||||
Answer<?> answer = invocation -> {
|
||||
if (invocation.getMethod().equals(furthestDirectionMethod)) {
|
||||
chasedRef.set(invocation.getArgument(0));
|
||||
chaserRef.set(invocation.getArgument(1));
|
||||
}
|
||||
return invocation.callRealMethod();
|
||||
};
|
||||
try (MockedStatic<Util> ignored = Mockito.mockStatic(Util.class, answer)) {
|
||||
call(redGhost::doMove, context, result -> "An exception occurred while invoking doMove");
|
||||
}
|
||||
|
||||
assertSame(chased, chasedRef.get(), context, result -> "doMove did not call furthestDirection with chased = " + chased);
|
||||
assertSame(redGhost, chaserRef.get(), context, result -> "doMove did not call furthestDirection with chaser = " + redGhost);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTurnLeft() {
|
||||
call(redGhost::doMove, context, result -> "An exception occurred while invoking doMove");
|
||||
|
||||
assertEquals(Direction.LEFT, redGhost.getDirection(), context, result -> "Red ghost does not face the correct direction");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMove() {
|
||||
call(redGhost::doMove, context, result -> "An exception occurred while invoking doMove");
|
||||
|
||||
assertEquals(startX - 1, redGhost.getX(), context, result -> "Red ghost's x-coordinate is incorrect");
|
||||
assertEquals(startY, redGhost.getY(), context, result -> "Red ghost's y-coordinate is incorrect");
|
||||
}
|
||||
}
|
50
solution/H01/src/main/java/h01/BlueGhost.java
Normal file
50
solution/H01/src/main/java/h01/BlueGhost.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
package h01;
|
||||
|
||||
import org.tudalgo.algoutils.student.annotation.SolutionOnly;
|
||||
import org.tudalgo.algoutils.student.annotation.StudentImplementationRequired;
|
||||
|
||||
import fopbot.Robot;
|
||||
import h01.template.Families;
|
||||
import h01.template.Ghost;
|
||||
import h01.template.TickBased;
|
||||
|
||||
/**
|
||||
* The {@link BlueGhost} is a {@link Robot} that looks like a blue ghost.
|
||||
* It tries to move in a circle.
|
||||
*/
|
||||
public class BlueGhost extends Robot implements Ghost, TickBased {
|
||||
/**
|
||||
* Creates a new {@link BlueGhost} at the given position.
|
||||
*
|
||||
* @param x the x-coordinate
|
||||
* @param y the y-coordinate
|
||||
*/
|
||||
public BlueGhost(int x, int y) {
|
||||
super(x, y, Families.GHOST_BLUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns the robot to the right and then moves in the first direction that is
|
||||
* clear.
|
||||
*/
|
||||
@Override
|
||||
@StudentImplementationRequired("H2.1")
|
||||
public void doMove() {
|
||||
turnRight();
|
||||
while (!isFrontClear()) {
|
||||
turnLeft();
|
||||
}
|
||||
move();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns the robot to the right.
|
||||
*
|
||||
*/
|
||||
@SolutionOnly
|
||||
private void turnRight() {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
turnLeft();
|
||||
}
|
||||
}
|
||||
}
|
23
solution/H01/src/main/java/h01/GameController.java
Normal file
23
solution/H01/src/main/java/h01/GameController.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package h01;
|
||||
|
||||
import h01.template.GameControllerTemplate;
|
||||
|
||||
/**
|
||||
* The {@link GameController} class is responsible for controlling the game.
|
||||
*/
|
||||
public class GameController extends GameControllerTemplate {
|
||||
/**
|
||||
* Creates a new {@link GameController} object and sets up the game.
|
||||
*/
|
||||
public GameController() {
|
||||
setup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player has won the game.
|
||||
*/
|
||||
@Override
|
||||
public boolean checkWinCondition() {
|
||||
return pacman.getNumberOfCoins() == totalCoins;
|
||||
}
|
||||
}
|
16
solution/H01/src/main/java/h01/Main.java
Normal file
16
solution/H01/src/main/java/h01/Main.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
package h01;
|
||||
|
||||
/**
|
||||
* Main entry point in executing the program.
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
/**
|
||||
* Main entry point in executing the program.
|
||||
*
|
||||
* @param args program arguments, currently ignored
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
new GameController().startGame();
|
||||
}
|
||||
}
|
53
solution/H01/src/main/java/h01/OrangeGhost.java
Normal file
53
solution/H01/src/main/java/h01/OrangeGhost.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
package h01;
|
||||
|
||||
import org.tudalgo.algoutils.student.annotation.StudentImplementationRequired;
|
||||
|
||||
import fopbot.Robot;
|
||||
import h01.template.Families;
|
||||
import h01.template.Ghost;
|
||||
import h01.template.TickBased;
|
||||
|
||||
/**
|
||||
* {@link OrangeGhost} is a {@link Robot} that looks like a orange ghost.
|
||||
* It tries to move in a straight line and alternates between turning left and
|
||||
* right.
|
||||
*/
|
||||
public class OrangeGhost extends Robot implements Ghost, TickBased {
|
||||
/**
|
||||
* Creates a new {@link OrangeGhost} at the given position.
|
||||
*
|
||||
* @param x the x-coordinate
|
||||
* @param y the y-coordinate
|
||||
*/
|
||||
public OrangeGhost(int x, int y) {
|
||||
super(x, y, Families.GHOST_ORANGE);
|
||||
}
|
||||
|
||||
private boolean leftTurnNext = false;
|
||||
|
||||
/**
|
||||
* Moves the robot in a straight line if possible.
|
||||
* If the robot cannot move forward, it turns left or right until there is no
|
||||
* wall in front.
|
||||
* The robot alternates between turning left and right.
|
||||
*/
|
||||
@Override
|
||||
@StudentImplementationRequired("H2.3")
|
||||
public void doMove() {
|
||||
if (isFrontClear()) {
|
||||
move();
|
||||
return;
|
||||
} else {
|
||||
while (!isFrontClear()) {
|
||||
if (leftTurnNext) {
|
||||
turnLeft();
|
||||
} else {
|
||||
turnLeft();
|
||||
turnLeft();
|
||||
turnLeft();
|
||||
}
|
||||
}
|
||||
leftTurnNext = !leftTurnNext;
|
||||
}
|
||||
}
|
||||
}
|
74
solution/H01/src/main/java/h01/Pacman.java
Normal file
74
solution/H01/src/main/java/h01/Pacman.java
Normal file
|
@ -0,0 +1,74 @@
|
|||
package h01;
|
||||
|
||||
import org.tudalgo.algoutils.student.annotation.SolutionOnly;
|
||||
import org.tudalgo.algoutils.student.annotation.StudentImplementationRequired;
|
||||
|
||||
import fopbot.Direction;
|
||||
import fopbot.Robot;
|
||||
import h01.template.Controllable;
|
||||
import h01.template.Families;
|
||||
import h01.template.TickBased;
|
||||
|
||||
/**
|
||||
* {@link Pacman} is a {@link Robot} that can be controlled by the user and
|
||||
* looks like Pacman.
|
||||
* It can move in four directions and pick up coins.
|
||||
*/
|
||||
public class Pacman extends Robot implements Controllable, TickBased {
|
||||
/**
|
||||
* Creates a new {@link Pacman} at the given position.
|
||||
*
|
||||
* @param x the x-coordinate
|
||||
* @param y the y-coordinate
|
||||
*/
|
||||
public Pacman(int x, int y) {
|
||||
super(x, y, Families.PACMAN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the key input of the user.
|
||||
* The keys 0, 1, 2, 3 represent the arrow keys up, right, down, left.
|
||||
* If the key is not in this range, the method does nothing.
|
||||
* If the key is in the range, the robot turns in the corresponding direction,
|
||||
* moves one field and collects a coin if there is one.
|
||||
*
|
||||
* @param k the int value of the pressed key
|
||||
*/
|
||||
@Override
|
||||
@StudentImplementationRequired("H1.1")
|
||||
public void handleKeyInput(int k) {
|
||||
if (k < 0 || k > 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (k == 0) {
|
||||
turnDirection(Direction.UP);
|
||||
} else if (k == 1) {
|
||||
turnDirection(Direction.RIGHT);
|
||||
} else if (k == 2) {
|
||||
turnDirection(Direction.DOWN);
|
||||
} else {
|
||||
turnDirection(Direction.LEFT);
|
||||
}
|
||||
|
||||
if (isFrontClear()) {
|
||||
move();
|
||||
}
|
||||
|
||||
if (isOnACoin()) {
|
||||
pickCoin();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns the robot in the given direction.
|
||||
*
|
||||
* @param dir the direction to turn to
|
||||
*/
|
||||
@SolutionOnly
|
||||
private void turnDirection(Direction dir) {
|
||||
while (getDirection() != dir) {
|
||||
turnLeft();
|
||||
}
|
||||
}
|
||||
}
|
50
solution/H01/src/main/java/h01/PinkGhost.java
Normal file
50
solution/H01/src/main/java/h01/PinkGhost.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
package h01;
|
||||
|
||||
import org.tudalgo.algoutils.student.annotation.StudentImplementationRequired;
|
||||
|
||||
import fopbot.Robot;
|
||||
import h01.template.Families;
|
||||
import h01.template.Ghost;
|
||||
import h01.template.TickBased;
|
||||
import h01.template.Util;
|
||||
|
||||
/**
|
||||
* The {@link PinkGhost} is a {@link Robot} that looks like a pink ghost.
|
||||
* It tries to move in a random direction.
|
||||
*/
|
||||
public class PinkGhost extends Robot implements Ghost, TickBased {
|
||||
/**
|
||||
* Creates a new {@link PinkGhost} at the given position.
|
||||
*
|
||||
* @param x the x-coordinate
|
||||
* @param y the y-coordinate
|
||||
*/
|
||||
public PinkGhost(int x, int y) {
|
||||
super(x, y, Families.GHOST_PINK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds in how many directions the ghost can move and then turns a random
|
||||
* amount of times to the left.
|
||||
* The ghost then moves forward or turns to the left until it can move forward.
|
||||
*/
|
||||
@Override
|
||||
@StudentImplementationRequired("H2.2")
|
||||
public void doMove() {
|
||||
int freeLanes = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
turnLeft();
|
||||
if (isFrontClear()) {
|
||||
freeLanes++;
|
||||
}
|
||||
}
|
||||
|
||||
int rand = Util.getRandomInteger(1, freeLanes);
|
||||
for (int i = 0; i < rand; i++) {
|
||||
do {
|
||||
turnLeft();
|
||||
} while (!isFrontClear());
|
||||
}
|
||||
move();
|
||||
}
|
||||
}
|
57
solution/H01/src/main/java/h01/RedGhost.java
Normal file
57
solution/H01/src/main/java/h01/RedGhost.java
Normal file
|
@ -0,0 +1,57 @@
|
|||
package h01;
|
||||
|
||||
import org.tudalgo.algoutils.student.annotation.SolutionOnly;
|
||||
import org.tudalgo.algoutils.student.annotation.StudentImplementationRequired;
|
||||
|
||||
import fopbot.Direction;
|
||||
import fopbot.Robot;
|
||||
import h01.template.Families;
|
||||
import h01.template.Ghost;
|
||||
import h01.template.TickBased;
|
||||
import h01.template.Util;
|
||||
|
||||
/**
|
||||
* The {@link RedGhost} is a {@link Robot} that looks like a red ghost.
|
||||
* It tries to move in the direction of the chased robot.
|
||||
*/
|
||||
public class RedGhost extends Robot implements Ghost, TickBased {
|
||||
private final Robot chased;
|
||||
|
||||
/**
|
||||
* Creates a new {@link RedGhost} at the given position.
|
||||
*
|
||||
* @param x the x-coordinate
|
||||
* @param y the y-coordinate
|
||||
* @param chased the robot that is being chased
|
||||
*/
|
||||
public RedGhost(int x, int y, Robot chased) {
|
||||
super(x, y, Families.GHOST_RED);
|
||||
this.chased = chased;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the robot in the direction of the chased robot.
|
||||
*/
|
||||
@Override
|
||||
@StudentImplementationRequired("H2.4")
|
||||
public void doMove() {
|
||||
turnDirection(Util.furthestDirection(chased, this));
|
||||
while (!isFrontClear()) {
|
||||
turnLeft();
|
||||
}
|
||||
move();
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns the robot in the given direction.
|
||||
*
|
||||
* @param dir the direction to turn to
|
||||
*/
|
||||
@SolutionOnly
|
||||
private void turnDirection(Direction dir) {
|
||||
while (getDirection() != dir) {
|
||||
turnLeft();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package h01.template;
|
||||
|
||||
public interface Controllable {
|
||||
void handleKeyInput(int k);
|
||||
}
|
36
solution/H01/src/main/java/h01/template/Families.java
Normal file
36
solution/H01/src/main/java/h01/template/Families.java
Normal file
|
@ -0,0 +1,36 @@
|
|||
package h01.template;
|
||||
|
||||
import fopbot.RobotFamily;
|
||||
import fopbot.SvgBasedRobotFamily;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class Families {
|
||||
public static RobotFamily GHOST_ORANGE = new SvgBasedRobotFamily(
|
||||
"GHOST_ORANGE",
|
||||
"/robots/ghost_orange.svg",
|
||||
"/robots/ghost_orange.svg",
|
||||
Color.ORANGE);
|
||||
public static RobotFamily GHOST_BLUE = new SvgBasedRobotFamily(
|
||||
"GHOST_BLUE",
|
||||
"/robots/ghost_blue.svg",
|
||||
"/robots/ghost_blue.svg",
|
||||
Color.BLUE);
|
||||
public static RobotFamily GHOST_RED = new SvgBasedRobotFamily(
|
||||
"GHOST_RED",
|
||||
"/robots/ghost_red.svg",
|
||||
"/robots/ghost_red.svg",
|
||||
Color.RED);
|
||||
public static RobotFamily GHOST_PINK = new SvgBasedRobotFamily(
|
||||
"GHOST_PINK",
|
||||
"/robots/ghost_pink.svg",
|
||||
"/robots/ghost_pink.svg",
|
||||
Color.PINK);
|
||||
public static RobotFamily PACMAN = new SvgBasedRobotFamily(
|
||||
"PACMAN",
|
||||
"/robots/pacman.svg",
|
||||
"/robots/pacman.svg",
|
||||
Color.YELLOW,
|
||||
270,
|
||||
270);
|
||||
}
|
|
@ -0,0 +1,378 @@
|
|||
package h01.template;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import fopbot.Coin;
|
||||
import fopbot.ColorProfile;
|
||||
import fopbot.GuiPanel;
|
||||
import fopbot.PaintUtils;
|
||||
import fopbot.Robot;
|
||||
import fopbot.World;
|
||||
import h01.BlueGhost;
|
||||
import h01.OrangeGhost;
|
||||
import h01.Pacman;
|
||||
import h01.PinkGhost;
|
||||
import h01.RedGhost;
|
||||
|
||||
/**
|
||||
* A {@link GameControllerTemplate} controls the game loop and the
|
||||
* {@link Robot}s and checks the win condition.
|
||||
*/
|
||||
public abstract class GameControllerTemplate {
|
||||
/**
|
||||
* The {@link Timer} that controls the game loop.
|
||||
*/
|
||||
private final Timer gameLoopTimer = new Timer();
|
||||
|
||||
/**
|
||||
* The {@link GameInputHandler} that handles the input of the user.
|
||||
*/
|
||||
private final GameInputHandler inputHandler = new GameInputHandler();
|
||||
|
||||
/**
|
||||
* The total umber of coins in the map.
|
||||
*/
|
||||
protected int totalCoins;
|
||||
|
||||
/**
|
||||
* The {@link Robot}s that are controlled by the {@link GameControllerTemplate}.
|
||||
*/
|
||||
protected final ArrayList<Robot> robots = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The {@link Pacman} {@link Robot}.
|
||||
*/
|
||||
protected Robot pacman;
|
||||
|
||||
/**
|
||||
* The {@link BlueGhost} {@link Robot}.
|
||||
*/
|
||||
protected Robot blue;
|
||||
|
||||
/**
|
||||
* The {@link OrangeGhost} {@link Robot}.
|
||||
*/
|
||||
protected Robot orange;
|
||||
|
||||
/**
|
||||
* The {@link PinkGhost} {@link Robot}.
|
||||
*/
|
||||
protected Robot pink;
|
||||
|
||||
/**
|
||||
* The {@link RedGhost} {@link Robot}.
|
||||
*/
|
||||
protected Robot red;
|
||||
|
||||
private Point ghostField = new Point(4, 4);
|
||||
|
||||
/**
|
||||
* A {@link Map} that maps a {@link Robot} to the amount of ticks that have
|
||||
* passed since the last tick action.
|
||||
*/
|
||||
private final Map<Robot, Integer> robotTicks = new HashMap<>();
|
||||
|
||||
/**
|
||||
* The {@link TimerTask} that is executed every tick.
|
||||
*/
|
||||
private final TimerTask gameLoopTask = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (final Robot robot : GameControllerTemplate.this.robots) {
|
||||
if (!(robot instanceof final TickBased tb)) {
|
||||
continue;
|
||||
}
|
||||
if (!GameControllerTemplate.this.robotTicks.containsKey(robot)) {
|
||||
GameControllerTemplate.this.robotTicks.put(robot, 0);
|
||||
}
|
||||
if (GameControllerTemplate.this.robotTicks.get(robot) < tb.getUpdateDelay()) {
|
||||
GameControllerTemplate.this.robotTicks.put(robot,
|
||||
GameControllerTemplate.this.robotTicks.get(robot) + 1);
|
||||
continue;
|
||||
}
|
||||
GameControllerTemplate.this.robotTicks.put(robot, 0);
|
||||
// do tick action
|
||||
if (robot instanceof final Pacman r) {
|
||||
r.handleKeyInput(
|
||||
GameControllerTemplate.this.inputHandler.getDirection());
|
||||
} else if (robot instanceof final Ghost r) {
|
||||
r.doMove();
|
||||
}
|
||||
}
|
||||
// check win condition
|
||||
if (checkWinCondition())
|
||||
stopGame(true);
|
||||
if (checkLoseCondition())
|
||||
stopGame(false);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the {@link h01.Pacman} {@link Robot}.
|
||||
*
|
||||
* @return the {@link h01.Pacman} {@link Robot}
|
||||
*/
|
||||
public Robot getPacman() {
|
||||
return pacman;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link BlueGhost} {@link Robot}.
|
||||
*
|
||||
* @return the {@link BlueGhost} {@link Robot}
|
||||
*/
|
||||
public Robot getBlue() {
|
||||
return blue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link OrangeGhost} {@link Robot}.
|
||||
*
|
||||
* @return the {@link OrangeGhost} {@link Robot}
|
||||
*/
|
||||
public Robot getOrange() {
|
||||
return orange;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link PinkGhost} {@link Robot}.
|
||||
*
|
||||
* @return the {@link PinkGhost} {@link Robot}
|
||||
*/
|
||||
public Robot getPink() {
|
||||
return pink;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link RedGhost} {@link Robot}.
|
||||
*
|
||||
* @return the {@link RedGhost} {@link Robot}
|
||||
*/
|
||||
public Robot getRed() {
|
||||
return red;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the game loop.
|
||||
*/
|
||||
public void startGame() {
|
||||
System.out.println("Starting game...");
|
||||
this.gameLoopTimer.scheduleAtFixedRate(this.gameLoopTask, 0, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the game loop.
|
||||
*/
|
||||
public void stopGame(boolean won) {
|
||||
this.gameLoopTimer.cancel();
|
||||
endscreen(won ? Color.GREEN : Color.RED);
|
||||
}
|
||||
|
||||
public void endscreen(Color color) {
|
||||
World.getGlobalWorld().getGuiPanel().setColorProfile(
|
||||
ColorProfile.DEFAULT.toBuilder()
|
||||
.backgroundColorDark(Color.BLACK)
|
||||
.backgroundColorLight(Color.BLACK)
|
||||
.fieldColorDark(color)
|
||||
.fieldColorLight(color)
|
||||
.innerBorderColorLight(color)
|
||||
.innerBorderColorDark(color)
|
||||
.wallColorDark(Color.BLUE)
|
||||
.wallColorLight(Color.BLUE)
|
||||
.outerBorderColorDark(Color.BLUE)
|
||||
.outerBorderColorLight(Color.BLUE)
|
||||
.coinColorDark(color)
|
||||
.coinColorLight(color)
|
||||
.build());
|
||||
World.getGlobalWorld().getGuiPanel().updateGui();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the game.
|
||||
*/
|
||||
protected void setup() {
|
||||
setupWorld();
|
||||
setupTheme();
|
||||
setupRobots();
|
||||
totalCoins = 2;// World.getHeight()*World.getWidth()-2;
|
||||
setupCoins(totalCoins);
|
||||
this.inputHandler.install();
|
||||
}
|
||||
|
||||
public void setupTheme() {
|
||||
World.getGlobalWorld().getGuiPanel().setColorProfile(
|
||||
ColorProfile.DEFAULT.toBuilder()
|
||||
.backgroundColorDark(Color.BLACK)
|
||||
.backgroundColorLight(Color.BLACK)
|
||||
.fieldColorDark(Color.BLACK)
|
||||
.fieldColorLight(Color.BLACK)
|
||||
.innerBorderColorLight(Color.BLACK)
|
||||
.innerBorderColorDark(Color.BLACK)
|
||||
.wallColorDark(Color.BLUE)
|
||||
.wallColorLight(Color.BLUE)
|
||||
.outerBorderColorDark(Color.BLUE)
|
||||
.outerBorderColorLight(Color.BLUE)
|
||||
.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the {@link World} and adds the {@link Robot}s to it.
|
||||
*/
|
||||
public void setupWorld() {
|
||||
World.setSize(9, 9);
|
||||
|
||||
World.getGlobalWorld().setGuiPanel(new GuiPanel(World.getGlobalWorld()) {
|
||||
@Override
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
protected void drawCoin(final Coin c, final Graphics g, final boolean evadeRobots) {
|
||||
final var g2d = (Graphics2D) g;
|
||||
final var oldColor = g2d.getColor();
|
||||
g2d.setColor(getColorProfile().getCoinColor());
|
||||
final Rectangle2D fieldBounds = scale(PaintUtils.getFieldBounds(c, world));
|
||||
final double radius = scale(5d);
|
||||
g2d.fill(
|
||||
new Ellipse2D.Double(
|
||||
fieldBounds.getCenterX() - radius,
|
||||
fieldBounds.getCenterY() - radius,
|
||||
2 * radius,
|
||||
2 * radius));
|
||||
}
|
||||
});
|
||||
|
||||
World.setDelay(0);
|
||||
World.setVisible(true);
|
||||
World.getGlobalWorld().setDrawTurnedOffRobots(false);
|
||||
|
||||
World.placeVerticalWall(0, 3);
|
||||
World.placeVerticalWall(0, 4);
|
||||
World.placeVerticalWall(0, 5);
|
||||
|
||||
World.placeVerticalWall(1, 2);
|
||||
World.placeVerticalWall(1, 4);
|
||||
World.placeVerticalWall(1, 6);
|
||||
|
||||
World.placeVerticalWall(2, 2);
|
||||
World.placeVerticalWall(2, 3);
|
||||
World.placeVerticalWall(2, 5);
|
||||
World.placeVerticalWall(2, 6);
|
||||
|
||||
World.placeVerticalWall(3, 4);
|
||||
World.placeVerticalWall(3, 7);
|
||||
|
||||
World.placeVerticalWall(4, 4);
|
||||
World.placeVerticalWall(4, 1);
|
||||
|
||||
World.placeVerticalWall(5, 2);
|
||||
World.placeVerticalWall(5, 3);
|
||||
World.placeVerticalWall(5, 5);
|
||||
World.placeVerticalWall(5, 6);
|
||||
|
||||
World.placeVerticalWall(6, 2);
|
||||
World.placeVerticalWall(6, 4);
|
||||
World.placeVerticalWall(6, 6);
|
||||
|
||||
World.placeVerticalWall(7, 3);
|
||||
World.placeVerticalWall(7, 4);
|
||||
World.placeVerticalWall(7, 5);
|
||||
|
||||
World.placeHorizontalWall(1, 0);
|
||||
World.placeHorizontalWall(1, 1);
|
||||
World.placeHorizontalWall(1, 6);
|
||||
World.placeHorizontalWall(1, 7);
|
||||
|
||||
World.placeHorizontalWall(2, 0);
|
||||
World.placeHorizontalWall(2, 7);
|
||||
|
||||
World.placeHorizontalWall(3, 0);
|
||||
World.placeHorizontalWall(3, 2);
|
||||
World.placeHorizontalWall(3, 5);
|
||||
|
||||
World.placeHorizontalWall(4, 1);
|
||||
World.placeHorizontalWall(4, 3);
|
||||
World.placeHorizontalWall(4, 6);
|
||||
|
||||
World.placeHorizontalWall(5, 2);
|
||||
World.placeHorizontalWall(5, 5);
|
||||
World.placeHorizontalWall(5, 7);
|
||||
|
||||
World.placeHorizontalWall(6, 0);
|
||||
World.placeHorizontalWall(6, 7);
|
||||
|
||||
World.placeHorizontalWall(7, 0);
|
||||
World.placeHorizontalWall(7, 1);
|
||||
World.placeHorizontalWall(7, 6);
|
||||
World.placeHorizontalWall(7, 7);
|
||||
|
||||
World.getGlobalWorld().setFieldColor(ghostField.x, ghostField.y, Color.YELLOW);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the {@link Robot}s to the {@link World}.
|
||||
*/
|
||||
public void setupRobots() {
|
||||
this.robots.add(pacman = new Pacman(4, 3));
|
||||
this.robots.add(blue = new BlueGhost(ghostField.x, ghostField.y));
|
||||
this.robots.add(orange = new OrangeGhost(ghostField.x, ghostField.y));
|
||||
this.robots.add(pink = new PinkGhost(ghostField.x, ghostField.y));
|
||||
this.robots.add(red = new RedGhost(ghostField.x, ghostField.y, pacman));
|
||||
}
|
||||
|
||||
public void setupCoins(int numberOfCoins) {
|
||||
if (numberOfCoins > World.getHeight() * World.getWidth() - 2) {
|
||||
throw new IllegalArgumentException("Too many coins for this world size.");
|
||||
}
|
||||
|
||||
ArrayList<Point> Fields = new ArrayList<>();
|
||||
for (int y = 0; y < World.getHeight(); y++) {
|
||||
for (int x = 0; x < World.getWidth(); x++) {
|
||||
if (!((x == ghostField.x && y == ghostField.y) || x == pacman.getX() && y == pacman.getY()))
|
||||
Fields.add(new Point(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < numberOfCoins; i++) {
|
||||
int randomIndex = (int) (Math.random() * Fields.size());
|
||||
Point spot = Fields.remove(randomIndex);
|
||||
World.putCoins(spot.x, spot.y, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the win condition.
|
||||
*
|
||||
* @return Returns true if the game is won.
|
||||
*/
|
||||
public abstract boolean checkWinCondition();
|
||||
|
||||
/**
|
||||
* Checks the lose condition.
|
||||
*
|
||||
* @return Returns true if the game is lost.
|
||||
*/
|
||||
public boolean checkLoseCondition() {
|
||||
boolean gameDone = pacman.getX() == orange.getX() && pacman.getY() == orange.getY();
|
||||
|
||||
if (pacman.getX() == blue.getX() && pacman.getY() == blue.getY()) {
|
||||
gameDone = true;
|
||||
}
|
||||
|
||||
if (pacman.getX() == pink.getX() && pacman.getY() == pink.getY()) {
|
||||
gameDone = true;
|
||||
}
|
||||
|
||||
if (pacman.getX() == red.getX() && pacman.getY() == red.getY()) {
|
||||
gameDone = true;
|
||||
}
|
||||
return gameDone;
|
||||
}
|
||||
}
|
108
solution/H01/src/main/java/h01/template/GameInputHandler.java
Normal file
108
solution/H01/src/main/java/h01/template/GameInputHandler.java
Normal file
|
@ -0,0 +1,108 @@
|
|||
package h01.template;
|
||||
|
||||
import fopbot.Direction;
|
||||
import fopbot.World;
|
||||
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* A {@link GameInputHandler} handles the input of the user.
|
||||
*/
|
||||
public class GameInputHandler {
|
||||
/**
|
||||
* The {@link fopbot.Direction} to turn to. If {@code -1} the robot should not turn.
|
||||
*/
|
||||
private final AtomicInteger direction = new AtomicInteger(-1);
|
||||
/**
|
||||
* If {@code true} the robot should put a coin on the current field.
|
||||
*/
|
||||
private final AtomicBoolean shouldPutCoins = new AtomicBoolean(false);
|
||||
/**
|
||||
* If {@code true} the robot should pick a coin from the current field.
|
||||
*/
|
||||
private final AtomicBoolean shouldPickCoins = new AtomicBoolean(false);
|
||||
|
||||
/**
|
||||
* Parses the inputs to a direction.
|
||||
*
|
||||
* @param keysPressed the keys pressed
|
||||
* @return the direction or null if no direction is pressed
|
||||
*/
|
||||
public static Direction getDirectionFromKeysPressed(final Set<Integer> keysPressed) {
|
||||
final Map<Direction, List<Integer>> directionKeys = Map.of(
|
||||
Direction.UP, List.of(KeyEvent.VK_UP, KeyEvent.VK_W),
|
||||
Direction.LEFT, List.of(KeyEvent.VK_LEFT, KeyEvent.VK_A),
|
||||
Direction.DOWN, List.of(KeyEvent.VK_DOWN, KeyEvent.VK_S),
|
||||
Direction.RIGHT, List.of(KeyEvent.VK_RIGHT, KeyEvent.VK_D)
|
||||
);
|
||||
final Set<Direction> pressedDirections = new HashSet<>();
|
||||
for (final Direction direction : directionKeys.keySet()) {
|
||||
for (final Integer key : directionKeys.get(direction)) {
|
||||
if (keysPressed.contains(key)) {
|
||||
pressedDirections.add(direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pressedDirections.size() == 1) {
|
||||
return pressedDirections.iterator().next();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs the {@link GameInputHandler} to the {@link World}.
|
||||
*/
|
||||
public void install() {
|
||||
World.getGlobalWorld().getInputHandler().addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyTyped(final KeyEvent e) {
|
||||
updateKeysPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(final KeyEvent e) {
|
||||
updateKeysPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(final KeyEvent e) {
|
||||
updateKeysPressed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the {@link #direction}, {@link #shouldPutCoins} and {@link #shouldPickCoins} based on the pressed keys.
|
||||
*/
|
||||
protected void updateKeysPressed() {
|
||||
this.direction.set(
|
||||
Optional.ofNullable(getDirectionFromKeysPressed(World.getGlobalWorld().getInputHandler().getKeysPressed()))
|
||||
.map(Enum::ordinal)
|
||||
.orElse(-1)
|
||||
);
|
||||
this.shouldPickCoins.set(
|
||||
World.getGlobalWorld().getInputHandler().getKeysPressed().contains(java.awt.event.KeyEvent.VK_SPACE)
|
||||
);
|
||||
this.shouldPutCoins.set(
|
||||
World.getGlobalWorld().getInputHandler().getKeysPressed().contains(java.awt.event.KeyEvent.VK_R)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current {@link fopbot.Direction} to turn to. If {@code -1} the robot should not turn.
|
||||
*
|
||||
* @return the current {@link fopbot.Direction} to turn to. If {@code -1} the robot should not turn.
|
||||
*/
|
||||
public int getDirection() {
|
||||
return this.direction.get();
|
||||
}
|
||||
}
|
5
solution/H01/src/main/java/h01/template/Ghost.java
Normal file
5
solution/H01/src/main/java/h01/template/Ghost.java
Normal file
|
@ -0,0 +1,5 @@
|
|||
package h01.template;
|
||||
|
||||
public interface Ghost {
|
||||
void doMove();
|
||||
}
|
15
solution/H01/src/main/java/h01/template/TickBased.java
Normal file
15
solution/H01/src/main/java/h01/template/TickBased.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package h01.template;
|
||||
|
||||
/**
|
||||
* An interface that enables an object to be updated every n-th tick.
|
||||
*/
|
||||
public interface TickBased {
|
||||
/**
|
||||
* Returns the number of ticks between two updates.
|
||||
*
|
||||
* @return the number of ticks between two updates
|
||||
*/
|
||||
default int getUpdateDelay() {
|
||||
return 1;
|
||||
}
|
||||
}
|
55
solution/H01/src/main/java/h01/template/Util.java
Normal file
55
solution/H01/src/main/java/h01/template/Util.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
package h01.template;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import fopbot.Direction;
|
||||
import fopbot.Robot;
|
||||
|
||||
/**
|
||||
* Utility class for the ghosts
|
||||
*/
|
||||
public class Util {
|
||||
|
||||
private static Random rnd = new Random();
|
||||
|
||||
/**
|
||||
* Returns a random integer between min and max (both inclusive)
|
||||
*
|
||||
* @param min the minimum value
|
||||
* @param max the maximum value
|
||||
* @return a random integer between min and max (both inclusive)
|
||||
*/
|
||||
public static int getRandomInteger(int min, int max) {
|
||||
return min + rnd.nextInt(max - min + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the direction in which the robot is the closest to the chaser
|
||||
*
|
||||
* @param pacman the robot that is being chased
|
||||
* @param chaser the robot that is chasing
|
||||
* @return the direction in which the robot is the closest to the chaser
|
||||
*/
|
||||
public static Direction furthestDirection(Robot pacman, Robot chaser) {
|
||||
int px = pacman.getX();
|
||||
int py = pacman.getY();
|
||||
int cx = chaser.getX();
|
||||
int cy = chaser.getY();
|
||||
|
||||
int xdelta = Math.abs(px - cx);
|
||||
int ydelta = Math.abs(py - cy);
|
||||
|
||||
if (xdelta > ydelta) {
|
||||
if (cx > px)
|
||||
return Direction.LEFT;
|
||||
else
|
||||
return Direction.RIGHT;
|
||||
} else {
|
||||
if (cy > py)
|
||||
return Direction.DOWN;
|
||||
else
|
||||
return Direction.UP;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
67
solution/H01/src/main/resources/robots/ghost_blue.svg
Normal file
67
solution/H01/src/main/resources/robots/ghost_blue.svg
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||
|
||||
<svg
|
||||
height="800px"
|
||||
width="800px"
|
||||
version="1.1"
|
||||
id="Layer_1"
|
||||
viewBox="0 0 512.001 512.001"
|
||||
xml:space="preserve"
|
||||
sodipodi:docname="ghost_blue.svg"
|
||||
inkscape:version="1.3.2 (091e20e, 2023-11-25, custom)"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"><defs
|
||||
id="defs8" /><sodipodi:namedview
|
||||
id="namedview8"
|
||||
pagecolor="#505050"
|
||||
bordercolor="#eeeeee"
|
||||
borderopacity="1"
|
||||
inkscape:showpageshadow="0"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:zoom="1.49875"
|
||||
inkscape:cx="399.33278"
|
||||
inkscape:cy="400"
|
||||
inkscape:window-width="2560"
|
||||
inkscape:window-height="1377"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="Layer_1" />
|
||||
<path
|
||||
style="fill:#555bff;fill-opacity:1"
|
||||
d="M248.399,0.135C135.421,4.152,47.514,100.436,47.514,213.484V508.8c0,2.792,3.432,4.127,5.319,2.069 l57.191-62.39c3.756-4.098,10.216-4.098,13.971,0l55.336,60.365c3.858,4.209,10.493,4.209,14.35,0l55.334-60.365 c3.756-4.098,10.216-4.098,13.971,0l55.334,60.365c3.858,4.209,10.493,4.209,14.35,0l55.336-60.365 c3.756-4.098,10.216-4.098,13.971,0l57.191,62.39c1.887,2.059,5.319,0.724,5.319-2.069V208.486 C464.489,90.819,367.009-4.082,248.399,0.135z"
|
||||
id="path1" />
|
||||
<path
|
||||
style="fill:#325ca9;fill-opacity:1"
|
||||
d="M151.758,227.632c0-107.205,79.072-199.275,183.593-211.938 C308.687,4.707,279.273-0.963,248.399,0.135C135.421,4.152,47.514,100.436,47.514,213.484V508.8c0,2.792,3.432,4.127,5.319,2.069 l57.191-62.39c3.755-4.098,10.216-4.098,13.971,0l27.762,30.285V227.632H151.758z"
|
||||
id="path2" />
|
||||
<path
|
||||
style="fill:#FFFFFF;"
|
||||
d="M186.385,303.255L186.385,303.255c-31.001,0-56.132-25.131-56.132-56.132v-20.412 c0-31.001,25.131-56.132,56.132-56.132l0,0c31.001,0,56.132,25.131,56.132,56.132v20.412 C242.515,278.124,217.385,303.255,186.385,303.255z"
|
||||
id="path3" />
|
||||
<path
|
||||
style="fill:#E4EAF6;"
|
||||
d="M217.002,293.049c-31.001,0-56.132-25.131-56.132-56.132v-20.412 c0-18.952,9.419-35.676,23.803-45.839c-30.201,0.912-54.421,25.621-54.421,56.045v20.412c0,31.001,25.131,56.132,56.132,56.132 c12.048,0,23.184-3.831,32.327-10.292C218.139,292.98,217.579,293.049,217.002,293.049z"
|
||||
id="path4" />
|
||||
<path
|
||||
style="fill:#82B9FF;"
|
||||
d="M201.693,262.431L201.693,262.431c-11.273,0-20.412-9.138-20.412-20.412v-10.205 c0-11.273,9.138-20.412,20.412-20.412l0,0c11.273,0,20.412,9.138,20.412,20.412v10.205 C222.105,253.294,212.966,262.431,201.693,262.431z"
|
||||
id="path5" />
|
||||
<path
|
||||
style="fill:#FFFFFF;"
|
||||
d="M325.619,303.255L325.619,303.255c-31.001,0-56.132-25.131-56.132-56.132v-20.412 c0-31.001,25.131-56.132,56.132-56.132l0,0c31.001,0,56.132,25.131,56.132,56.132v20.412 C381.75,278.124,356.619,303.255,325.619,303.255z"
|
||||
id="path6" />
|
||||
<path
|
||||
style="fill:#E4EAF6;"
|
||||
d="M356.236,293.049c-31.001,0-56.132-25.131-56.132-56.132v-20.412 c0-18.952,9.419-35.676,23.804-45.839c-30.201,0.912-54.421,25.621-54.421,56.045v20.412c0,31.001,25.131,56.132,56.132,56.132 c12.048,0,23.184-3.831,32.327-10.292C357.374,292.98,356.814,293.049,356.236,293.049z"
|
||||
id="path7" />
|
||||
<path
|
||||
style="fill:#82B9FF;"
|
||||
d="M340.927,262.431L340.927,262.431c-11.273,0-20.412-9.138-20.412-20.412v-10.205 c0-11.273,9.138-20.412,20.412-20.412l0,0c11.273,0,20.412,9.138,20.412,20.412v10.205 C361.339,253.294,352.201,262.431,340.927,262.431z"
|
||||
id="path8" />
|
||||
</svg>
|
After Width: | Height: | Size: 3.6 KiB |
31
solution/H01/src/main/resources/robots/ghost_orange.svg
Normal file
31
solution/H01/src/main/resources/robots/ghost_orange.svg
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||
<svg height="800px" width="800px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
viewBox="0 0 512.001 512.001" xml:space="preserve">
|
||||
<path style="fill:#FFA05A;" d="M248.399,0.135C135.421,4.152,47.514,100.436,47.514,213.484V508.8c0,2.792,3.432,4.127,5.319,2.069
|
||||
l57.191-62.39c3.756-4.098,10.216-4.098,13.971,0l55.336,60.365c3.858,4.209,10.493,4.209,14.35,0l55.334-60.365
|
||||
c3.756-4.098,10.216-4.098,13.971,0l55.334,60.365c3.858,4.209,10.493,4.209,14.35,0l55.336-60.365
|
||||
c3.756-4.098,10.216-4.098,13.971,0l57.191,62.39c1.887,2.059,5.319,0.724,5.319-2.069V208.486
|
||||
C464.489,90.819,367.009-4.082,248.399,0.135z"/>
|
||||
<path style="fill:#F08C46;" d="M151.758,227.632c0-107.205,79.072-199.275,183.593-211.938
|
||||
C308.687,4.707,279.273-0.963,248.399,0.135C135.421,4.152,47.514,100.436,47.514,213.484V508.8c0,2.792,3.432,4.127,5.319,2.069
|
||||
l57.191-62.39c3.755-4.098,10.216-4.098,13.971,0l27.762,30.285V227.632H151.758z"/>
|
||||
<path style="fill:#FFFFFF;" d="M186.385,303.255L186.385,303.255c-31.001,0-56.132-25.131-56.132-56.132v-20.412
|
||||
c0-31.001,25.131-56.132,56.132-56.132l0,0c31.001,0,56.132,25.131,56.132,56.132v20.412
|
||||
C242.515,278.124,217.385,303.255,186.385,303.255z"/>
|
||||
<path style="fill:#E4EAF6;" d="M217.002,293.049c-31.001,0-56.132-25.131-56.132-56.132v-20.412
|
||||
c0-18.952,9.419-35.676,23.803-45.839c-30.201,0.912-54.421,25.621-54.421,56.045v20.412c0,31.001,25.131,56.132,56.132,56.132
|
||||
c12.048,0,23.184-3.831,32.327-10.292C218.139,292.98,217.579,293.049,217.002,293.049z"/>
|
||||
<path style="fill:#82B9FF;" d="M201.693,262.431L201.693,262.431c-11.273,0-20.412-9.138-20.412-20.412v-10.205
|
||||
c0-11.273,9.138-20.412,20.412-20.412l0,0c11.273,0,20.412,9.138,20.412,20.412v10.205
|
||||
C222.105,253.294,212.966,262.431,201.693,262.431z"/>
|
||||
<path style="fill:#FFFFFF;" d="M325.619,303.255L325.619,303.255c-31.001,0-56.132-25.131-56.132-56.132v-20.412
|
||||
c0-31.001,25.131-56.132,56.132-56.132l0,0c31.001,0,56.132,25.131,56.132,56.132v20.412
|
||||
C381.75,278.124,356.619,303.255,325.619,303.255z"/>
|
||||
<path style="fill:#E4EAF6;" d="M356.236,293.049c-31.001,0-56.132-25.131-56.132-56.132v-20.412
|
||||
c0-18.952,9.419-35.676,23.804-45.839c-30.201,0.912-54.421,25.621-54.421,56.045v20.412c0,31.001,25.131,56.132,56.132,56.132
|
||||
c12.048,0,23.184-3.831,32.327-10.292C357.374,292.98,356.814,293.049,356.236,293.049z"/>
|
||||
<path style="fill:#82B9FF;" d="M340.927,262.431L340.927,262.431c-11.273,0-20.412-9.138-20.412-20.412v-10.205
|
||||
c0-11.273,9.138-20.412,20.412-20.412l0,0c11.273,0,20.412,9.138,20.412,20.412v10.205
|
||||
C361.339,253.294,352.201,262.431,340.927,262.431z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 2.6 KiB |
67
solution/H01/src/main/resources/robots/ghost_pink.svg
Normal file
67
solution/H01/src/main/resources/robots/ghost_pink.svg
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||
|
||||
<svg
|
||||
height="800px"
|
||||
width="800px"
|
||||
version="1.1"
|
||||
id="Layer_1"
|
||||
viewBox="0 0 512.001 512.001"
|
||||
xml:space="preserve"
|
||||
sodipodi:docname="ghost_pink.svg"
|
||||
inkscape:version="1.3.2 (091e20e, 2023-11-25, custom)"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"><defs
|
||||
id="defs8" /><sodipodi:namedview
|
||||
id="namedview8"
|
||||
pagecolor="#505050"
|
||||
bordercolor="#eeeeee"
|
||||
borderopacity="1"
|
||||
inkscape:showpageshadow="0"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:zoom="1.49875"
|
||||
inkscape:cx="399.33278"
|
||||
inkscape:cy="400"
|
||||
inkscape:window-width="2560"
|
||||
inkscape:window-height="1377"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="Layer_1" />
|
||||
<path
|
||||
style="fill:#e555ff;fill-opacity:1"
|
||||
d="M248.399,0.135C135.421,4.152,47.514,100.436,47.514,213.484V508.8c0,2.792,3.432,4.127,5.319,2.069 l57.191-62.39c3.756-4.098,10.216-4.098,13.971,0l55.336,60.365c3.858,4.209,10.493,4.209,14.35,0l55.334-60.365 c3.756-4.098,10.216-4.098,13.971,0l55.334,60.365c3.858,4.209,10.493,4.209,14.35,0l55.336-60.365 c3.756-4.098,10.216-4.098,13.971,0l57.191,62.39c1.887,2.059,5.319,0.724,5.319-2.069V208.486 C464.489,90.819,367.009-4.082,248.399,0.135z"
|
||||
id="path1" />
|
||||
<path
|
||||
style="fill:#c53bd0;fill-opacity:1"
|
||||
d="M151.758,227.632c0-107.205,79.072-199.275,183.593-211.938 C308.687,4.707,279.273-0.963,248.399,0.135C135.421,4.152,47.514,100.436,47.514,213.484V508.8c0,2.792,3.432,4.127,5.319,2.069 l57.191-62.39c3.755-4.098,10.216-4.098,13.971,0l27.762,30.285V227.632H151.758z"
|
||||
id="path2" />
|
||||
<path
|
||||
style="fill:#FFFFFF;"
|
||||
d="M186.385,303.255L186.385,303.255c-31.001,0-56.132-25.131-56.132-56.132v-20.412 c0-31.001,25.131-56.132,56.132-56.132l0,0c31.001,0,56.132,25.131,56.132,56.132v20.412 C242.515,278.124,217.385,303.255,186.385,303.255z"
|
||||
id="path3" />
|
||||
<path
|
||||
style="fill:#E4EAF6;"
|
||||
d="M217.002,293.049c-31.001,0-56.132-25.131-56.132-56.132v-20.412 c0-18.952,9.419-35.676,23.803-45.839c-30.201,0.912-54.421,25.621-54.421,56.045v20.412c0,31.001,25.131,56.132,56.132,56.132 c12.048,0,23.184-3.831,32.327-10.292C218.139,292.98,217.579,293.049,217.002,293.049z"
|
||||
id="path4" />
|
||||
<path
|
||||
style="fill:#82B9FF;"
|
||||
d="M201.693,262.431L201.693,262.431c-11.273,0-20.412-9.138-20.412-20.412v-10.205 c0-11.273,9.138-20.412,20.412-20.412l0,0c11.273,0,20.412,9.138,20.412,20.412v10.205 C222.105,253.294,212.966,262.431,201.693,262.431z"
|
||||
id="path5" />
|
||||
<path
|
||||
style="fill:#FFFFFF;"
|
||||
d="M325.619,303.255L325.619,303.255c-31.001,0-56.132-25.131-56.132-56.132v-20.412 c0-31.001,25.131-56.132,56.132-56.132l0,0c31.001,0,56.132,25.131,56.132,56.132v20.412 C381.75,278.124,356.619,303.255,325.619,303.255z"
|
||||
id="path6" />
|
||||
<path
|
||||
style="fill:#E4EAF6;"
|
||||
d="M356.236,293.049c-31.001,0-56.132-25.131-56.132-56.132v-20.412 c0-18.952,9.419-35.676,23.804-45.839c-30.201,0.912-54.421,25.621-54.421,56.045v20.412c0,31.001,25.131,56.132,56.132,56.132 c12.048,0,23.184-3.831,32.327-10.292C357.374,292.98,356.814,293.049,356.236,293.049z"
|
||||
id="path7" />
|
||||
<path
|
||||
style="fill:#82B9FF;"
|
||||
d="M340.927,262.431L340.927,262.431c-11.273,0-20.412-9.138-20.412-20.412v-10.205 c0-11.273,9.138-20.412,20.412-20.412l0,0c11.273,0,20.412,9.138,20.412,20.412v10.205 C361.339,253.294,352.201,262.431,340.927,262.431z"
|
||||
id="path8" />
|
||||
</svg>
|
After Width: | Height: | Size: 3.6 KiB |
67
solution/H01/src/main/resources/robots/ghost_red.svg
Normal file
67
solution/H01/src/main/resources/robots/ghost_red.svg
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||
|
||||
<svg
|
||||
height="800px"
|
||||
width="800px"
|
||||
version="1.1"
|
||||
id="Layer_1"
|
||||
viewBox="0 0 512.001 512.001"
|
||||
xml:space="preserve"
|
||||
sodipodi:docname="ghost_red.svg"
|
||||
inkscape:version="1.3.2 (091e20e, 2023-11-25, custom)"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"><defs
|
||||
id="defs8" /><sodipodi:namedview
|
||||
id="namedview8"
|
||||
pagecolor="#505050"
|
||||
bordercolor="#eeeeee"
|
||||
borderopacity="1"
|
||||
inkscape:showpageshadow="0"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:zoom="1.49875"
|
||||
inkscape:cx="399.33278"
|
||||
inkscape:cy="400"
|
||||
inkscape:window-width="2560"
|
||||
inkscape:window-height="1377"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="Layer_1" />
|
||||
<path
|
||||
style="fill:#ff4040;fill-opacity:1"
|
||||
d="M248.399,0.135C135.421,4.152,47.514,100.436,47.514,213.484V508.8c0,2.792,3.432,4.127,5.319,2.069 l57.191-62.39c3.756-4.098,10.216-4.098,13.971,0l55.336,60.365c3.858,4.209,10.493,4.209,14.35,0l55.334-60.365 c3.756-4.098,10.216-4.098,13.971,0l55.334,60.365c3.858,4.209,10.493,4.209,14.35,0l55.336-60.365 c3.756-4.098,10.216-4.098,13.971,0l57.191,62.39c1.887,2.059,5.319,0.724,5.319-2.069V208.486 C464.489,90.819,367.009-4.082,248.399,0.135z"
|
||||
id="path1" />
|
||||
<path
|
||||
style="fill:#d03b3b;fill-opacity:1"
|
||||
d="M151.758,227.632c0-107.205,79.072-199.275,183.593-211.938 C308.687,4.707,279.273-0.963,248.399,0.135C135.421,4.152,47.514,100.436,47.514,213.484V508.8c0,2.792,3.432,4.127,5.319,2.069 l57.191-62.39c3.755-4.098,10.216-4.098,13.971,0l27.762,30.285V227.632H151.758z"
|
||||
id="path2" />
|
||||
<path
|
||||
style="fill:#FFFFFF;"
|
||||
d="M186.385,303.255L186.385,303.255c-31.001,0-56.132-25.131-56.132-56.132v-20.412 c0-31.001,25.131-56.132,56.132-56.132l0,0c31.001,0,56.132,25.131,56.132,56.132v20.412 C242.515,278.124,217.385,303.255,186.385,303.255z"
|
||||
id="path3" />
|
||||
<path
|
||||
style="fill:#E4EAF6;"
|
||||
d="M217.002,293.049c-31.001,0-56.132-25.131-56.132-56.132v-20.412 c0-18.952,9.419-35.676,23.803-45.839c-30.201,0.912-54.421,25.621-54.421,56.045v20.412c0,31.001,25.131,56.132,56.132,56.132 c12.048,0,23.184-3.831,32.327-10.292C218.139,292.98,217.579,293.049,217.002,293.049z"
|
||||
id="path4" />
|
||||
<path
|
||||
style="fill:#82B9FF;"
|
||||
d="M201.693,262.431L201.693,262.431c-11.273,0-20.412-9.138-20.412-20.412v-10.205 c0-11.273,9.138-20.412,20.412-20.412l0,0c11.273,0,20.412,9.138,20.412,20.412v10.205 C222.105,253.294,212.966,262.431,201.693,262.431z"
|
||||
id="path5" />
|
||||
<path
|
||||
style="fill:#FFFFFF;"
|
||||
d="M325.619,303.255L325.619,303.255c-31.001,0-56.132-25.131-56.132-56.132v-20.412 c0-31.001,25.131-56.132,56.132-56.132l0,0c31.001,0,56.132,25.131,56.132,56.132v20.412 C381.75,278.124,356.619,303.255,325.619,303.255z"
|
||||
id="path6" />
|
||||
<path
|
||||
style="fill:#E4EAF6;"
|
||||
d="M356.236,293.049c-31.001,0-56.132-25.131-56.132-56.132v-20.412 c0-18.952,9.419-35.676,23.804-45.839c-30.201,0.912-54.421,25.621-54.421,56.045v20.412c0,31.001,25.131,56.132,56.132,56.132 c12.048,0,23.184-3.831,32.327-10.292C357.374,292.98,356.814,293.049,356.236,293.049z"
|
||||
id="path7" />
|
||||
<path
|
||||
style="fill:#82B9FF;"
|
||||
d="M340.927,262.431L340.927,262.431c-11.273,0-20.412-9.138-20.412-20.412v-10.205 c0-11.273,9.138-20.412,20.412-20.412l0,0c11.273,0,20.412,9.138,20.412,20.412v10.205 C361.339,253.294,352.201,262.431,340.927,262.431z"
|
||||
id="path8" />
|
||||
</svg>
|
After Width: | Height: | Size: 3.6 KiB |
61
solution/H01/src/main/resources/robots/pacman.svg
Normal file
61
solution/H01/src/main/resources/robots/pacman.svg
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||
|
||||
<svg
|
||||
height="800px"
|
||||
width="800px"
|
||||
version="1.1"
|
||||
id="Layer_1"
|
||||
viewBox="0 0 512 512"
|
||||
xml:space="preserve"
|
||||
sodipodi:docname="gamer-svgrepo-com.svg"
|
||||
inkscape:version="1.3.2 (091e20e, 2023-11-25, custom)"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"><defs
|
||||
id="defs6" /><sodipodi:namedview
|
||||
id="namedview6"
|
||||
pagecolor="#505050"
|
||||
bordercolor="#eeeeee"
|
||||
borderopacity="1"
|
||||
inkscape:showpageshadow="0"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:zoom="1.49875"
|
||||
inkscape:cx="399.66639"
|
||||
inkscape:cy="400"
|
||||
inkscape:window-width="2560"
|
||||
inkscape:window-height="1377"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="Layer_1" />
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<g
|
||||
id="g6"
|
||||
transform="translate(83.607539,4.4703637e-4)"><path
|
||||
style="fill:#ffd782"
|
||||
d="m 209.638,244.628 129.736,-95.594 c 6.241,-4.599 7.204,-13.545 2.155,-19.428 C 301.171,82.587 238.774,55.049 170.311,63.221 81.862,73.778 10.999,145.353 1.223,233.893 c -12.937,117.155 78.443,216.313 192.983,216.313 58.996,0 111.782,-26.358 147.389,-67.889 5.021,-5.856 3.992,-14.775 -2.218,-19.35 L 209.638,267.37 c -7.661,-5.645 -7.661,-17.096 0,-22.742 z"
|
||||
id="path1" /><path
|
||||
style="fill:#ffc36e"
|
||||
d="M 255.491,406.068 C 140.951,406.068 49.571,306.911 62.507,189.755 67.182,147.409 85.94,109.043 113.803,79.279 53.119,107.021 8.797,165.293 1.223,233.892 c -12.937,117.156 78.443,216.314 192.983,216.314 55.956,0 106.298,-23.738 141.721,-61.62 -24.506,11.197 -51.724,17.482 -80.436,17.482 z"
|
||||
id="path2" /><circle
|
||||
style="fill:#5b5d6e"
|
||||
cx="220.689"
|
||||
cy="150.06799"
|
||||
r="26.483"
|
||||
id="circle5" /><path
|
||||
style="fill:#464655"
|
||||
d="m 231.724,163.31 c -13.407,0 -24.276,-10.869 -24.276,-24.276 0,-5.134 1.614,-9.88 4.335,-13.802 -10.222,3.669 -17.577,13.351 -17.577,24.836 0,14.626 11.857,26.483 26.483,26.483 11.486,0 21.167,-7.354 24.836,-17.577 -3.921,2.72 -8.667,4.336 -13.801,4.336 z"
|
||||
id="path6" /></g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.3 KiB |
16
solution/H01/src/test/java/h01/ExampleJUnitTest.java
Normal file
16
solution/H01/src/test/java/h01/ExampleJUnitTest.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
package h01;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* An example JUnit test class.
|
||||
*/
|
||||
public class ExampleJUnitTest {
|
||||
|
||||
@Test
|
||||
public void testAddition() {
|
||||
assertEquals(2, 1 + 1);
|
||||
}
|
||||
}
|
1
solution/H01/version
Normal file
1
solution/H01/version
Normal file
|
@ -0,0 +1 @@
|
|||
0.1.0-SNAPSHOT
|
Loading…
Add table
Reference in a new issue