forked from FUT/codenjoy_client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
anatoliliotych
committed
Dec 4, 2014
1 parent
3596126
commit 021e692
Showing
5 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
How to use client? | ||
1. Install all requirements: | ||
``` | ||
pip install -r requirements.txt | ||
``` | ||
|
||
2. update necessary params in __init__.py | ||
|
||
3. for launch: | ||
``` | ||
python __init__.py | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from player import Player | ||
from codenjoy_connection import CodenjoyConnection | ||
|
||
|
||
try: | ||
name = 'anatoliliotych' # name which was used during registration | ||
port = '8080' # game port | ||
host = 'localhost' # game host | ||
game_url = 'codenjoy-contest/ws?' # game url | ||
|
||
url = "ws://{0}:{1}/{2}user={3}".format(host, port, game_url, name) | ||
player = Player() | ||
ws = CodenjoyConnection(url, player) | ||
ws.connect() | ||
ws.run_forever() | ||
except KeyboardInterrupt: | ||
ws.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from ws4py.client.threadedclient import WebSocketClient | ||
|
||
class CodenjoyConnection(WebSocketClient): | ||
def __init__(self, url, player): | ||
super(CodenjoyConnection, self).__init__(url) | ||
self.player = player | ||
|
||
def received_message(self, m): | ||
print "Received from server: %s" % (str(m)) | ||
self.player.process_data(m) | ||
self.send(self.player.make_step()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Player: | ||
def process_data(self,data): | ||
# process data here | ||
pass | ||
def make_step(self): | ||
# prepare response here | ||
# pass | ||
return "right=1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ws4py |