Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python2018
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Zoltán Strcuľa
python2018
Commits
19f98d1f
Commit
19f98d1f
authored
6 years ago
by
Zoltán Strcuľa
Browse files
Options
Downloads
Patches
Plain Diff
update
parent
b4f78f3f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
12-tic-tac-toe-client/ttt.py
+46
-48
46 additions, 48 deletions
12-tic-tac-toe-client/ttt.py
with
46 additions
and
48 deletions
12-tic-tac-toe-client/ttt.py
+
46
−
48
View file @
19f98d1f
...
...
@@ -144,65 +144,63 @@ async def process_status_request(request):
async
def
process_play_request
(
request
):
input_query
=
request
.
query
_string
params
=
request
.
query
output
=
{}
if
(
input_query
[
0
:
5
]
==
'
game=
'
):
all_query
=
input_query
.
split
(
'
&
'
)
if
(
len
(
all_query
)
==
4
):
game_id
=
all_query
[
0
][
5
:]
player_numb
=
all_query
[
1
][
7
:]
row
=
all_query
[
2
][
2
:]
column
=
all_query
[
3
][
2
:]
search_game
=
get_game
(
game_id
)
if
(
search_game
is
None
):
return
web
.
Response
(
text
=
"
Wrong game ID.
"
,
status
=
404
)
elif
(
search_game
.
is_finished
):
if
(
'
game
'
in
params
and
'
player
'
and
params
and
'
x
'
in
params
and
'
y
'
in
params
):
game_id
=
params
[
'
game
'
]
player_numb
=
params
[
'
player
'
]
row
=
params
[
'
x
'
]
column
=
params
[
'
y
'
]
search_game
=
get_game
(
game_id
)
if
(
search_game
is
None
):
return
web
.
Response
(
text
=
"
Wrong game ID.
"
,
status
=
404
)
elif
(
search_game
.
is_finished
):
output
[
'
status
'
]
=
'
bad
'
output
[
'
message
'
]
=
"
Game is over.
"
return
web
.
Response
(
text
=
json
.
dumps
(
output
,
indent
=
4
,
ensure_ascii
=
False
))
else
:
if
((
int
(
player_numb
)
!=
1
and
int
(
player_numb
)
!=
2
)
or
int
(
player_numb
)
!=
search_game
.
whos_turn
):
output
[
'
status
'
]
=
'
bad
'
output
[
'
message
'
]
=
"
Game is ov
er.
"
output
[
'
message
'
]
=
"
Wrong player numb
er.
"
return
web
.
Response
(
text
=
json
.
dumps
(
output
,
indent
=
4
,
ensure_ascii
=
False
))
else
:
if
((
int
(
player_numb
)
!=
1
and
int
(
player_numb
)
!=
2
)
or
int
(
player_numb
)
!=
search_game
.
whos_turn
):
output
[
'
status
'
]
=
'
bad
'
output
[
'
message
'
]
=
"
Wrong player number.
"
return
web
.
Response
(
text
=
json
.
dumps
(
output
,
indent
=
4
,
ensure_ascii
=
False
))
try
:
if
(
int
(
row
)
not
in
range
(
0
,
3
)
or
int
(
column
)
not
in
range
(
0
,
3
)):
output
[
'
status
'
]
=
'
bad
'
output
[
'
message
'
]
=
"
Wrong move in game, x and y must be 0, 1 or 2.
"
return
web
.
Response
(
text
=
json
.
dumps
(
output
,
indent
=
4
,
ensure_ascii
=
False
))
except
:
try
:
if
(
int
(
row
)
not
in
range
(
0
,
3
)
or
int
(
column
)
not
in
range
(
0
,
3
)):
output
[
'
status
'
]
=
'
bad
'
output
[
'
message
'
]
=
"
x and y must be
number
.
"
output
[
'
message
'
]
=
"
Wrong move in game,
x and y must be
0, 1 or 2
.
"
return
web
.
Response
(
text
=
json
.
dumps
(
output
,
indent
=
4
,
ensure_ascii
=
False
))
if
(
search_game
.
board
[
int
(
column
)][
int
(
row
)]
==
0
):
search_game
.
board
[
int
(
column
)][
int
(
row
)]
=
search_game
.
whos_turn
if
(
search_game
.
whos_turn
==
1
):
search_game
.
whos_turn
=
2
else
:
search_game
.
whos_turn
=
1
except
:
output
[
'
status
'
]
=
'
bad
'
output
[
'
message
'
]
=
"
x and y must be number.
"
return
web
.
Response
(
text
=
json
.
dumps
(
output
,
indent
=
4
,
ensure_ascii
=
False
))
if
(
search_game
.
board
[
int
(
column
)][
int
(
row
)]
==
0
):
search_game
.
board
[
int
(
column
)][
int
(
row
)]
=
search_game
.
whos_turn
if
(
search_game
.
whos_turn
==
1
):
search_game
.
whos_turn
=
2
else
:
search_game
.
whos_turn
=
1
search_game
.
board_empty
=
False
search_game
.
board_empty
=
False
output
[
'
status
'
]
=
'
ok
'
output
[
'
status
'
]
=
'
ok
'
is_game_done
=
{}
is_game_done
=
search_game
.
status
()
if
(
'
winner
'
in
is_game_done
):
search_game
.
is_finished
=
True
is_game_done
=
{}
is_game_done
=
search_game
.
status
()
if
(
'
winner
'
in
is_game_done
):
search_game
.
is_finished
=
True
return
web
.
Response
(
text
=
json
.
dumps
(
output
,
indent
=
4
,
ensure_ascii
=
False
))
else
:
output
[
'
status
'
]
=
'
bad
'
output
[
'
message
'
]
=
"
Given position is already marked
"
return
web
.
Response
(
text
=
json
.
dumps
(
output
,
indent
=
4
,
ensure_ascii
=
False
))
return
web
.
Response
(
text
=
json
.
dumps
(
output
,
indent
=
4
,
ensure_ascii
=
False
))
else
:
output
[
'
status
'
]
=
'
bad
'
output
[
'
message
'
]
=
"
Given position is already marked
"
return
web
.
Response
(
text
=
json
.
dumps
(
output
,
indent
=
4
,
ensure_ascii
=
False
))
else
:
return
web
.
Response
(
text
=
"
Wrong play request.
"
,
status
=
404
)
else
:
return
web
.
Response
(
text
=
"
Wrong play request.
"
,
status
=
404
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment