Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs2-19wi
project09
Commits
c79f7b56
Commit
c79f7b56
authored
5 years ago
by
Nicholas Ardavin
Browse files
Options
Download
Email Patches
Plain Diff
Updates for 2020 & replays
parent
f08d2f7b
master
No related merge requests found
Pipeline
#29562
canceled with stage
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/play/Bot.java
+2
-2
src/play/Bot.java
src/play/Play.java
+25
-25
src/play/Play.java
with
27 additions
and
27 deletions
+27
-27
src/play/Bot.java
View file @
c79f7b56
...
...
@@ -10,8 +10,8 @@ import edu.caltech.cs2.project08.game.Move;
import
edu.caltech.cs2.project08.game.SimpleEvaluator
;
public
class
Bot
{
public
static
final
String
BOT_NAME
=
"
FILL_IN_YOUR_NAME_FROM_SERVER
"
;
public
static
final
String
BOT_PASS
=
"
FILL_IN_YOUR_PASSWORD_FROM_SERVER
"
;
public
static
final
String
BOT_NAME
=
"
MyBotName
"
;
public
static
final
String
BOT_PASS
=
"
MyBotPassword
"
;
private
Evaluator
<
ArrayBoard
>
evaluator
;
private
BoardFactory
<
ArrayBoard
>
boardFactory
;
...
...
This diff is collapsed.
Click to expand it.
src/play/Play.java
View file @
c79f7b56
...
...
@@ -13,7 +13,7 @@ import java.net.*;
import
java.util.*
;
public
class
Play
{
public
static
final
String
SERVER
=
"http://
othello.countablethoughts.com
/"
;
public
static
final
String
SERVER
=
"http://
missing.coffee
/"
;
private
static
boolean
WAITING
=
false
;
public
static
JSONArray
bots
;
...
...
@@ -31,33 +31,16 @@ public class Play {
Socket
socket
=
IO
.
socket
(
SERVER
+
"?bot="
+
Bot
.
BOT_NAME
+
"&pw="
+
Bot
.
BOT_PASS
,
opts
);
socket
.
on
(
Socket
.
EVENT_CONNECT
,
(
arg
)
->
{
//
System.out.println("Connected to server.");
System
.
out
.
println
(
"Connected to server."
);
isConnected
=
true
;
}).
on
(
Socket
.
EVENT_DISCONNECT
,
(
arg
)
->
{
//
System.out.println("Disconnected from server.");
System
.
out
.
println
(
"Disconnected from server."
);
}).
on
(
"bad_connect"
,
(
arg
)
->
{
try
{
System
.
out
.
println
(((
JSONObject
)
arg
[
1
]).
getString
(
"message"
));
}
catch
(
JSONException
e
)
{
}
System
.
exit
(
1
);
})
/*.on("gameover", (arg) -> {
JSONObject obj = (JSONObject) arg[0];
try {
String result = obj.getString("result");
if (result.equals("draw")) {
System.out.println("The game was a draw!");
}
else {
System.out.println(result + " won!");
}
} catch (JSONException e) {
e.printStackTrace();
}
if (WAITING) {
System.out.print(">> ");
WAITING = false;
}
})*/
.
on
(
"failure"
,
(
arg
)
->
{
}).
on
(
"failure"
,
(
arg
)
->
{
JSONObject
obj
=
(
JSONObject
)
arg
[
0
];
String
message
=
""
;
try
{
...
...
@@ -84,7 +67,8 @@ public class Play {
}
catch
(
JSONException
e
)
{
}
if
(!
games
.
contains
(
gameId
))
{
System
.
out
.
println
(
"Watch the game at: "
+
SERVER
+
"watch?game="
+
gameId
);
System
.
out
.
println
(
"Watch the game LIVE at: "
+
SERVER
+
"watch?game="
+
gameId
);
System
.
out
.
println
(
"Replay will be available at: "
+
SERVER
+
"replay?game="
+
gameId
);
games
.
add
(
gameId
);
}
...
...
@@ -99,8 +83,22 @@ public class Play {
int
finalOpTime
=
opTime
;
String
finalId
=
gameId
;
Thread
thread
=
new
Thread
(()
->
{
Move
best
=
bot
.
getBestMove
(
finalPos
,
finalMyTime
,
finalOpTime
);
socket
.
emit
(
"move"
,
best
,
finalId
);
Move
best
;
try
{
best
=
bot
.
getBestMove
(
finalPos
,
finalMyTime
,
finalOpTime
);
socket
.
emit
(
"move"
,
best
,
finalId
);
}
catch
(
Exception
e
)
{
// If the searcher crashed, return a purposeful bad move
e
.
printStackTrace
();
try
{
Thread
.
sleep
(
100
);
}
catch
(
Exception
e2
)
{}
System
.
out
.
println
(
"The move searcher crashed. Sending a bad move to end the game."
);
System
.
out
.
print
(
">> "
);
best
=
new
Move
(-
1
);
socket
.
emit
(
"move"
,
best
,
finalId
);
}
});
thread
.
start
();
}).
on
(
"info"
,
(
arg
)
->
{
...
...
@@ -160,7 +158,9 @@ public class Play {
JSONObject
botObj
=
bots
.
getJSONObject
(
i
);
String
name
=
botObj
.
getString
(
"name"
);
String
status
=
botObj
.
getString
(
"status"
);
System
.
out
.
printf
(
"\t%s - %s%s\n"
,
name
,
status
,
name
.
equals
(
Bot
.
BOT_NAME
)
?
" - You"
:
""
);
if
(!
status
.
equals
(
"Not Connected"
))
{
System
.
out
.
printf
(
"\t%s - %s%s\n"
,
name
,
status
,
name
.
equals
(
Bot
.
BOT_NAME
)
?
" - You"
:
""
);
}
}
catch
(
JSONException
e
)
{
}
}
}
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help