Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanthat #1

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 Benoit Lacelle - SOLVEN
*
* 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
*
* http://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.
*/
package eu.solven.territory.app.mvc;

import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 Benoit Lacelle - SOLVEN
*
* 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
*
* http://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.
*/
package eu.solven.territory.app.mvc;

import java.util.Random;
Expand Down
15 changes: 15 additions & 0 deletions monolith/src/main/java/eu/solven/territory/snake/ISnakeCell.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 Benoit Lacelle - SOLVEN
*
* 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
*
* http://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.
*/
package eu.solven.territory.snake;

import eu.solven.territory.snake.strategies.dummy.WholeSnake;
Expand Down
25 changes: 20 additions & 5 deletions monolith/src/main/java/eu/solven/territory/snake/SnakeCell.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 Benoit Lacelle - SOLVEN
*
* 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
*
* http://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.
*/
package eu.solven.territory.snake;

import java.util.LinkedList;
Expand Down Expand Up @@ -32,15 +47,15 @@ public class SnakeCell extends SnakeOrApple implements ISnakeCell, IsSnake {

public static SnakeCell headToRight() {
WholeSnake wholeSnake = new WholeSnake(1, new LinkedList<>());
SnakeCell head = new SnakeCell(wholeSnake, true, 0, 0);
var head = new SnakeCell(wholeSnake, true, 0, 0);
wholeSnake.appendAsHead(head);

return head;
}

public static SnakeCell headToRight_canSmell(Supplier<Random> randomSupplier) {
WholeSnake wholeSnake = new WholeSnake_SmellApplesLoseWeightWithTime( randomSupplier, 1, new LinkedList<>());
SnakeCell head = new SnakeCell(wholeSnake, true, 0, 0);
WholeSnake wholeSnake = new WholeSnake_SmellApplesLoseWeightWithTime(randomSupplier, 1, new LinkedList<>());
var head = new SnakeCell(wholeSnake, true, 0, 0);
wholeSnake.appendAsHead(head);

return head;
Expand All @@ -50,10 +65,10 @@ public void newHead(int direction) {
ISnakeCell previousHead = whole.loseHead();

int previousHeadCellIndex = previousHead.getCellIndex();
SnakeCell behindNewHead = new SnakeCell(whole, false, previousHeadCellIndex, previousHead.getDirection());
var behindNewHead = new SnakeCell(whole, false, previousHeadCellIndex, previousHead.getDirection());
whole.appendAsHead(behindNewHead);

SnakeCell futureHead = new SnakeCell(whole, true, previousHeadCellIndex + 1, direction);
var futureHead = new SnakeCell(whole, true, previousHeadCellIndex + 1, direction);
whole.appendAsHead(futureHead);
// return futureHead;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 Benoit Lacelle - SOLVEN
*
* 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
*
* http://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.
*/
package eu.solven.territory.snake;

import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 Benoit Lacelle - SOLVEN
*
* 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
*
* http://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.
*/
package eu.solven.territory.snake.strategies.dummy;

import java.util.Collection;
Expand Down Expand Up @@ -66,7 +81,7 @@ public void loseTail() {
}

public WholeSnake copy() {
WholeSnake newSnake = new WholeSnake(uuid, getCapacity(), new LinkedList<>());
var newSnake = new WholeSnake(uuid, getCapacity(), new LinkedList<>());

LinkedList<ISnakeCell> newCells =
cells.stream().map(cell -> cell.editSnake(newSnake)).collect(Collectors.toCollection(LinkedList::new));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 Benoit Lacelle - SOLVEN
*
* 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
*
* http://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.
*/
package eu.solven.territory.snake.strategies.v1_cansmell;

import java.util.Deque;
Expand Down Expand Up @@ -56,7 +71,7 @@ private WholeSnake_SmellApplesLoseWeightWithTime(UUID uuid,
}

public WholeSnake copy() {
WholeSnake_SmellApplesLoseWeightWithTime newSnake = new WholeSnake_SmellApplesLoseWeightWithTime(this.getId(),
var newSnake = new WholeSnake_SmellApplesLoseWeightWithTime(this.getId(),
randomSupplier,
getCapacity(),
new LinkedList<>());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 Benoit Lacelle - SOLVEN
*
* 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
*
* http://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.
*/
package eu.solven.territory.snake.strategies.v2_multiplesnakes;

import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 Benoit Lacelle - SOLVEN
*
* 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
*
* http://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.
*/
package eu.solven.territory.snake.strategies.v2_multiplesnakes;

import java.util.concurrent.atomic.AtomicReference;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 Benoit Lacelle - SOLVEN
*
* 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
*
* http://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.
*/
package eu.solven.territory.snake.v0_only_snake;

import java.util.HashSet;
Expand Down Expand Up @@ -48,7 +63,7 @@ public GameOfSnake(SquareMap map) {

@Override
public IWorldOccupation<ISnakeWorldItem> cycle(IWorldOccupation<ISnakeWorldItem> occupation) {
int cyrrentCycle = cycleIndex.getAndIncrement();
var cyrrentCycle = cycleIndex.getAndIncrement();

IWorldOccupation<ISnakeWorldItem> rawCopy = rawCycle(occupation);

Expand All @@ -63,8 +78,8 @@ public IWorldOccupation<ISnakeWorldItem> cycle(IWorldOccupation<ISnakeWorldItem>
private IWorldOccupation<ISnakeWorldItem> rawCycle(IWorldOccupation<ISnakeWorldItem> occupation) {
IWorldOccupation<ISnakeWorldItem> rawCopy = occupation.mutableCopy();

int includeSelfRadius = 1;
int gameOfLifeRadius = 1;
var includeSelfRadius = 1;
var gameOfLifeRadius = 1;
IMapWindow<ISnakeWorldItem> windowBuffer = occupation.makeWindowBuffer(includeSelfRadius + gameOfLifeRadius);

SnakeTurnContext context = buildContext(occupation, windowBuffer);
Expand Down Expand Up @@ -129,9 +144,9 @@ private void growApples(SnakeTurnContext context, SnakeInRectangleOccupation sna
int worldSize = map.size();

// 1 apple plus one apple per 10x10 blocks
int targetNbApples = 1 + worldSize / (10 * 10);
var targetNbApples = 1 + worldSize / (10 * 10);

int missingApples = Math.max(0, targetNbApples - nbApples);
var missingApples = Math.max(0, targetNbApples - nbApples);

if (missingApples > 0) {
// Apples can pop anywhere, even under the snake
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023 Benoit Lacelle - SOLVEN
*
* 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
*
* http://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.
*/
package eu.solven.territory.snake.v0_only_snake;

import java.util.HashSet;
Expand Down Expand Up @@ -49,7 +64,7 @@ public GameOfSnake_Multiple(SquareMap map) {

@Override
public IWorldOccupation<ISnakeWorldItem> cycle(IWorldOccupation<ISnakeWorldItem> occupation) {
int cyrrentCycle = cycleIndex.getAndIncrement();
var cyrrentCycle = cycleIndex.getAndIncrement();

IWorldOccupation<ISnakeWorldItem> rawCopy = rawCycle(occupation);

Expand All @@ -64,8 +79,8 @@ public IWorldOccupation<ISnakeWorldItem> cycle(IWorldOccupation<ISnakeWorldItem>
private IWorldOccupation<ISnakeWorldItem> rawCycle(IWorldOccupation<ISnakeWorldItem> occupation) {
IWorldOccupation<ISnakeWorldItem> rawCopy = occupation.mutableCopy();

int includeSelfRadius = 1;
int gameOfLifeRadius = 1;
var includeSelfRadius = 1;
var gameOfLifeRadius = 1;
IMapWindow<ISnakeWorldItem> windowBuffer = occupation.makeWindowBuffer(includeSelfRadius + gameOfLifeRadius);

SnakeTurnContext context = buildContext(occupation, windowBuffer);
Expand Down Expand Up @@ -133,9 +148,9 @@ private void growApples(SnakeTurnContext context, MultipleSnakeInRectangleOccupa
int worldSize = map.size();

// 1 apple plus one apple per 10x10 blocks
int targetNbApples = 1 + worldSize / (10 * 10);
var targetNbApples = 1 + worldSize / (10 * 10);

int missingApples = Math.max(0, targetNbApples - nbApples);
var missingApples = Math.max(0, targetNbApples - nbApples);

if (missingApples > 0) {
// Apples can pop anywhere, even under the snake
Expand Down