Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
artificial-intelligence
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jak.moore
artificial-intelligence
Commits
70e39fec
Commit
70e39fec
authored
Mar 15, 2018
by
jak.moore
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
node
parent
e25aa278
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
180 additions
and
59 deletions
+180
-59
workspace.xml
.idea/workspace.xml
+124
-46
Actions.java
src/Actions.java
+1
-1
Main.java
src/Main.java
+38
-12
Node.java
src/Node.java
+17
-0
No files found.
.idea/workspace.xml
View file @
70e39fec
This diff is collapsed.
Click to expand it.
src/Actions.java
View file @
70e39fec
...
...
@@ -6,6 +6,6 @@ public enum Actions {
WOLF_LEFT_TO_BOAT
,
WOLF_RIGHT_TO_BOAT
,
WOLF_BOAT_TO_LEFT
,
WOLF_BOAT_TO_RIGHT
,
CHICKEN_RIGHT_TO_BOAT
,
CHICKEN_LEFT_TO_BOAT
,
CHICKEN_BOAT_TO_RIGHT
,
CHICKEN_BOAT_TO_LEFT
,
CHICKEN_BOAT_TO_RIGHT
,
CHICKEN_BOAT_TO_LEFT
,
VOID
}
src/Main.java
View file @
70e39fec
...
...
@@ -2,7 +2,7 @@ import java.util.ArrayList;
public
class
Main
{
private
boolean
planCompleted
=
false
;
private
static
boolean
planCompleted
=
false
;
public
static
void
main
(
String
[]
args
)
{
...
...
@@ -17,19 +17,40 @@ public class Main {
// Instantiating a new Game State object
GameState
gs
=
new
GameState
(
lBank
,
rBank
,
raft
,
true
);
//
Invoking get actions method and storing the results in an array
list
ArrayList
<
Actions
>
validActions
=
getActions
(
gs
);
//
Closed
list
ArrayList
<
GameState
>
closedList
=
new
ArrayList
(
);
// Array list to hold game states
ArrayList
<
GameState
>
newStates
=
new
ArrayList
();
ArrayList
<
Node
>
frontier
=
new
ArrayList
();
frontier
.
add
(
new
Node
(
Actions
.
VOID
,
gs
));
while
(
true
)
{
Node
firstNode
=
frontier
.
get
(
0
);
if
(
goalTest
(
firstNode
.
gs
))
{
System
.
out
.
print
(
"COMPLETE"
);
planCompleted
=
true
;
}
ArrayList
<
Actions
>
validActions
=
getActions
(
firstNode
.
gs
);
// Iterate through valid actions simulating their game state
for
(
Actions
a
:
validActions
)
{
gs
=
Simulate
(
gs
,
a
);
gs
=
Simulate
(
firstNode
.
gs
,
a
);
if
(!
closedList
.
contains
(
gs
))
{
// Storing possible game states in array list
newStates
.
add
(
gs
);
// Storing possible game states in frontier
frontier
.
add
(
new
Node
(
a
,
gs
));
}
}
closedList
.
add
(
firstNode
.
gs
);
}
...
...
@@ -39,7 +60,7 @@ public class Main {
private
static
ArrayList
<
Actions
>
getActions
(
GameState
gs
)
{
// Array list to hold possible actions
ArrayList
<
Actions
>
possibleActions
=
new
ArrayList
<>
();
ArrayList
<
Actions
>
possibleActions
=
new
ArrayList
();
// Counters to hold game information
int
wolvesOnLBank
=
0
;
...
...
@@ -53,7 +74,9 @@ public class Main {
// Getting current state of game
if
(
gs
.
raft
.
size
()
>
1
)
{
raftFull
=
true
;
}
for
(
int
i
:
gs
.
leftBank
)
{
...
...
@@ -238,10 +261,11 @@ public class Main {
}
return
gs
;
}
// Goal test method
public
boolean
goalTest
(
GameState
gs
)
{
public
static
boolean
goalTest
(
GameState
gs
)
{
int
lengthR
=
gs
.
rightBank
.
size
();
int
lengthL
=
gs
.
leftBank
.
size
();
...
...
@@ -293,7 +317,7 @@ public class Main {
}
// Check final counts
private
boolean
completed
(
int
wolves
,
int
chickens
)
{
private
static
boolean
completed
(
int
wolves
,
int
chickens
)
{
if
((
wolves
==
3
)
&&
(
chickens
==
3
))
{
...
...
@@ -303,7 +327,9 @@ public class Main {
}
else
{
return
false
;
}
}
}
src/Node.java
0 → 100644
View file @
70e39fec
public
class
Node
{
Node
parent
;
GameState
gs
;
public
Node
(
Actions
actionTaken
,
GameState
gs
)
{
this
.
gs
=
gs
;
}
public
void
setParent
(
Node
parent
)
{
this
.
parent
=
parent
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment