Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/main/java/NamedConnection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public record NamedConnection(String name, int r, int c) {

}
126 changes: 62 additions & 64 deletions src/main/java/io/github/auberonedu/equalsLivecode/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,78 +11,76 @@ public static void main(String[] args) {
// To start, look at Centroid.java
// BEFORE running the code, make a prediction of what the following will print:

Centroid locA = new Centroid(4, 9, "Salamander");
Centroid locB = new Centroid(4, 9, "Salamander");
// Centroid locA = new Centroid(4, 9, "Salamander");
// Centroid locB = new Centroid(4, 9, "Salamander");

System.out.println("Result of locA == locB " + (locA == locB));
System.out.println("Result of locA.equals(locB) " + locA.equals(locB));
// System.out.println("Result of locA == locB " + (locA == locB));
// System.out.println("Result of locA.equals(locB) " + locA.equals(locB));

//videoDemo();
videoDemo();
}

// We will look at this a bit later in the livecode, please ignore for first part
// We will look at this a bit later in the livecode, please ignore for first
// part
public static void videoDemo() {
List<char[][]> video = List.of(
// Frame 0: Salamander is at [2, 3] (all locations in [row, column] format)
// Food is at [4, 5]
new char[][]{{'.','.','.','.','.','.','.',},
{'.','.','.','.','.','.','.',},
{'.','.','.','s','.','.','.',},
{'.','.','.','.','.','.','.',},
{'.','.','.','.','.','f','.',},
{'.','.','.','.','.','.','.',}},

// Frame 2: Salamander is at [2, 4]
// Food is at [4, 5]
new char[][]{{'.','.','.','.','.','.','.',},
{'.','.','.','.','.','.','.',},
{'.','.','.','.','s','.','.',},
{'.','.','.','.','.','.','.',},
{'.','.','.','.','.','f','.',},
{'.','.','.','.','.','.','.',}},

// Frame 3: Salamander is at [2, 4] (it didn't move)
// Food is at [4, 5]
new char[][]{{'.','.','.','.','.','.','.',},
{'.','.','.','.','.','.','.',},
{'.','.','.','.','s','.','.',},
{'.','.','.','.','.','.','.',},
{'.','.','.','.','.','f','.',},
{'.','.','.','.','.','.','.',}},


// Frame 4: Salamander is at [3, 4]
// Food is at [4, 5]
new char[][]{{'.','.','.','.','.','.','.',},
{'.','.','.','.','.','.','.',},
{'.','.','.','.','.','.','.',},
{'.','.','.','.','s','.','.',},
{'.','.','.','.','.','f','.',},
{'.','.','.','.','.','.','.',}},

// Frame 5: Salamander is at [4, 4]
// Food is at [4, 5]
new char[][]{{'.','.','.','.','.','.','.',},
{'.','.','.','.','.','.','.',},
{'.','.','.','.','.','.','.',},
{'.','.','.','.','.','.','.',},
{'.','.','.','.','s','f','.',},
{'.','.','.','.','.','.','.',}},

// Frame 6: Salamander is at [4, 5]
// No food present (the salamander ate it!)
new char[][]{{'.','.','.','.','.','.','.',},
{'.','.','.','.','.','.','.',},
{'.','.','.','.','.','.','.',},
{'.','.','.','.','.','.','.',},
{'.','.','.','.','.','s','.',},
{'.','.','.','.','.','.','.',}}
);
// Frame 0: Salamander is at [2, 3] (all locations in [row, column] format)
// Food is at [4, 5]
new char[][] { { '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', 's', '.', '.', '.', },
{ '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', '.', 'f', '.', },
{ '.', '.', '.', '.', '.', '.', '.', } },

// Frame 2: Salamander is at [2, 4]
// Food is at [4, 5]
new char[][] { { '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', 's', '.', '.', },
{ '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', '.', 'f', '.', },
{ '.', '.', '.', '.', '.', '.', '.', } },

// Frame 3: Salamander is at [2, 4] (it didn't move)
// Food is at [4, 5]
new char[][] { { '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', 's', '.', '.', },
{ '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', '.', 'f', '.', },
{ '.', '.', '.', '.', '.', '.', '.', } },

// Frame 4: Salamander is at [3, 4]
// Food is at [4, 5]
new char[][] { { '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', 's', '.', '.', },
{ '.', '.', '.', '.', '.', 'f', '.', },
{ '.', '.', '.', '.', '.', '.', '.', } },

// Frame 5: Salamander is at [4, 4]
// Food is at [4, 5]
new char[][] { { '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', 's', 'f', '.', },
{ '.', '.', '.', '.', '.', '.', '.', } },

// Frame 6: Salamander is at [4, 5]
// No food present (the salamander ate it!)
new char[][] { { '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', '.', '.', '.', },
{ '.', '.', '.', '.', '.', 's', '.', },
{ '.', '.', '.', '.', '.', '.', '.', } });

Map<String, Character> legend = Map.of(
"Salamander", 's',
"Food", 'f'
);
"Salamander", 's',
"Food", 'f');

Finder finder = new Finder(legend);
Set<Centroid> salamanderLocations = finder.allLocations(video, "Salamander");
Expand Down
41 changes: 37 additions & 4 deletions src/main/java/io/github/auberonedu/equalsLivecode/Centroid.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,58 @@
package io.github.auberonedu.equalsLivecode;

import java.util.Objects;

public class Centroid {
private int r;
private int c;
private String name;

public Centroid(int r, int c, String name) {
this.r = r;
this.c = c;
this.name = name;
}

public int getR() {
return r;
return this.r;
}

public int getC() {
return c;
return this.c;
}

public String getName() {
return name;
return this.name;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Centroid other = (Centroid) obj;
if (r != other.r)
return false;
if (c != other.c)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + r;
result = prime * result + c;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
}