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

Update branch #179

Merged
merged 20 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
54a5632
bug to load a file fixed,
Benjum9 Jan 5, 2022
d47eb2c
Default name added for human player
Benjum9 Jan 5, 2022
9bf62ae
Merge branch 'main' into fix_bug_loading_a_game
S010MON Jan 6, 2022
2d88829
Refactor colour to use static reference, removes unused buttons
S010MON Jan 6, 2022
62862ae
Removes MiniMax from agents (because it sucks RAM ... and ass)
S010MON Jan 6, 2022
795342c
Removes MiniMax from agentFactory
S010MON Jan 6, 2022
fe8dc64
Heuristic-Maximise Number Of Groups
shirleydekoster Jan 6, 2022
537f6e2
Merge pull request #175 from S010MON/main
S010MON Jan 6, 2022
dbd778e
Adds type to MaxNumGroups
S010MON Jan 6, 2022
5f87a90
Merge pull request #165 from S010MON/fix_bug_loading_a_game
Benjum9 Jan 7, 2022
e2575ac
Merge pull request #174 from S010MON/Maximise_number_of_groups
shirleydekoster Jan 7, 2022
47f084f
adds sparsity heuristic
AlexHartmann00 Jan 7, 2022
473cd7b
makes sparsity heuristic calculate distance to nearest same-color tile.
AlexHartmann00 Jan 7, 2022
45657b1
Merge pull request #176 from S010MON/sparsityHeuristic
Giacomo-Terragni Jan 7, 2022
ac6947d
resets Random agent to uniform, adds num groups heuristic to tester
AlexHartmann00 Jan 7, 2022
0a039bb
Merge pull request #177 from S010MON/sparsitySettingsReset
Giacomo-Terragni Jan 7, 2022
fa35e61
'cleaned up the class + test class final version
Giacomo-Terragni Jan 7, 2022
22d81ac
'cleaned up the class + test class final version
Giacomo-Terragni Jan 7, 2022
c9585c3
adds sparsity & outer weighted heuristic to tester, fixes static clas…
AlexHartmann00 Jan 7, 2022
a864d7b
Merge pull request #178 from S010MON/sparsityOuterWeighted
Giacomo-Terragni Jan 7, 2022
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
Prev Previous commit
Next Next commit
'cleaned up the class + test class final version
final version'
  • Loading branch information
Giacomo-Terragni committed Jan 7, 2022
commit fa35e61816c6188f219e2004930433c21ceb6b7f
2 changes: 1 addition & 1 deletion .idea/misc.xml

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

4 changes: 3 additions & 1 deletion app/src/main/java/Bamboo/controller/heuristics/Sparsity.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public String getType() {
return "Sparsity";
}

class sparsityComparator implements Comparator<Vector> {
static class sparsityComparator implements Comparator<Vector> {
private Game game;

@Override
public int compare(Vector x, Vector y) {
Grid grid = game.getGrid();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package Bamboo.controller.heuristics;

import Bamboo.controller.Vector;
import Bamboo.model.Game;
import Bamboo.model.Grid;
import Bamboo.model.Tile;

import java.util.*;

public class SparsityAndOuterWeighted implements Heuristic {
private Game game;
@Override
public Vector getNextMove(Game game) {
this.game = game;
Comparator<Vector> comparator = new Sparsity.sparsityComparator();
Queue<Vector> queue = new PriorityQueue<>(game.getGrid().getAllVectors().size(),comparator);
ArrayList<Tile> tiles = (ArrayList<Tile>) game.getAllTiles();
Collections.shuffle(tiles);
for (Tile t : tiles) {
if (!t.isCouloured())
queue.add(t.getVector());
}
Vector v;
while (!queue.isEmpty()) {
v = queue.remove();
if (game.getGrid().isLegalMove(v, game.getCurrentPlayer().getColor()))
return v;
}
return null;
}

@Override
public String getType() {
return "Sparsity";
}

static class sparsityComparator implements Comparator<Vector> {

private Game game;

@Override
public int compare(Vector x, Vector y) {
Grid grid = game.getGrid();
Grid xgrid = grid.copy();
xgrid.setTile(x,game.getCurrentPlayer().getColor());
Grid ygrid = grid.copy();
ygrid.setTile(y,game.getCurrentPlayer().getColor());
int distX = 10000;
int distY = 10000;
Vector selectedVectorX = null;
Vector selectedVectorY = null;

for(Tile t : grid.getAllTiles()){
if(t.getColour() == game.getCurrentPlayer().getColor()){
if(t.getVector().distance(x) < distX){
distX = t.getVector().distance(x);
selectedVectorX = t.getVector();
}
if(t.getVector().distance(y) < distY){
distY = t.getVector().distance(y);
selectedVectorY = t.getVector();
}
}
}
Vector centerVector = new Vector(0,0,0);
int finalDistanceX = distX + selectedVectorX.distance(centerVector);
int finalDistanceY = distY + selectedVectorY.distance(centerVector);

return Integer.compare(finalDistanceX, -finalDistanceY);
}
}
}
1 change: 1 addition & 0 deletions app/src/main/java/saved/MiniMaxComparisons.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0,
3 changes: 3 additions & 0 deletions app/src/main/java/saved/MiniMaxComparisonsGiacomo.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1.0,
1.0,
1.0,
3 changes: 3 additions & 0 deletions app/src/main/java/saved/MiniMaxComparisonsGiacomo2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1.0,
1.0,
1.0,
Empty file.
Empty file.
Empty file.
38 changes: 38 additions & 0 deletions app/src/main/java/saved/bamboo_2021-12-09_1347
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Any lines that start with a '#' are ignored
#
# Settings
#
SOS
radius=5
name=MM Sorted
colour=RED
type=minimax
name=Ronald
colour=BLUE
type=random
EOS
#
# Start of tiles
# Layout: x,y,z,colour
SOT
1,0,-1,BLUE
3,0,-3,BLUE
5,0,-5,RED
0,5,-5,RED
2,-1,-1,BLUE
2,-2,0,BLUE
-1,-3,4,BLUE
-5,0,5,RED
-1,-4,5,BLUE
0,-5,5,RED
-5,2,3,RED
5,-5,0,RED
-4,-1,5,BLUE
-5,5,0,RED
1,-4,3,BLUE
2,3,-5,RED
-3,5,-2,RED
0,-1,1,BLUE
-3,-2,5,RED
-3,1,2,BLUE
EOT
87 changes: 87 additions & 0 deletions app/src/main/java/saved/bamboo_2021-12-09_1410
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Any lines that start with a '#' are ignored
#
# Settings
#
SOS
radius=5
name=MM Sorted
colour=RED
type=minimax
name=Ronald
colour=BLUE
type=random
EOS
#
# Start of tiles
# Layout: x,y,z,colour
SOT
2,0,-2,RED
4,0,-4,BLUE
5,0,-5,RED
1,-2,1,BLUE
-1,5,-4,BLUE
0,5,-5,RED
-4,1,3,BLUE
-2,2,0,RED
-5,1,4,BLUE
1,-1,0,RED
2,-1,-1,BLUE
3,-1,-2,BLUE
4,-1,-3,RED
5,-1,-4,RED
-1,0,1,BLUE
2,-3,1,BLUE
-4,4,0,BLUE
3,-5,2,BLUE
0,2,-2,BLUE
1,2,-3,RED
2,2,-4,BLUE
2,-2,0,RED
5,-2,-3,RED
-3,4,-1,RED
-4,3,1,RED
3,-4,1,RED
-2,0,2,BLUE
4,-3,-1,RED
5,-3,-2,BLUE
-1,-1,2,RED
4,-5,1,RED
-1,4,-3,RED
-1,-3,4,BLUE
-5,0,5,RED
1,4,-5,RED
-1,-2,3,BLUE
5,-4,-1,BLUE
-4,2,2,BLUE
-1,-4,5,RED
0,-5,5,RED
-1,1,0,BLUE
-5,2,3,RED
-4,0,4,BLUE
5,-5,0,RED
-3,0,3,RED
0,1,-1,RED
1,1,-2,BLUE
3,1,-4,RED
4,1,-5,BLUE
-4,-1,5,BLUE
-2,3,-1,BLUE
-5,5,0,RED
-2,-2,4,RED
0,-3,3,RED
-2,1,1,BLUE
1,-5,4,BLUE
-1,3,-2,RED
-4,5,-1,BLUE
-3,2,1,BLUE
0,-2,2,BLUE
1,-4,3,BLUE
1,3,-4,BLUE
2,3,-5,RED
-3,5,-2,RED
-5,3,2,BLUE
-3,-2,5,RED
1,-3,2,BLUE
-3,1,2,RED
2,-5,3,RED
EOT
5 changes: 5 additions & 0 deletions app/src/main/java/saved/test1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
0.5,
0.56,
0.55,
0.55,
0.62,
5 changes: 5 additions & 0 deletions app/src/main/java/saved/test1Giacomo.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
0.52,
0.52,
0.58,
0.58,
0.53,