Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zahra Rajabi
pymdptoolbox
Commits
9357eea8
Commit
9357eea8
authored
Feb 14, 2013
by
Steven Cordwell
Browse files
copy game status functions from RL tictactoe project
parent
b393d55f
Changes
1
Hide whitespace changes
Inline
Side-by-side
examples/tictactoe.py
View file @
9357eea8
# -*- coding: utf-8 -*-
import
mdp
class
TicTacToeMDP
(
object
):
""""""
def
__init__
(
self
):
""""""
pass
def
isLegal
(
state
,
action
):
""""""
if
state
[
action
]
==
0
:
return
True
else
:
return
False
def
isWon
(
state
):
""""""
wins
=
([
1
,
1
,
1
,
0
,
0
,
0
,
0
,
0
,
0
],
[
0
,
0
,
0
,
1
,
1
,
1
,
0
,
0
,
0
],
[
0
,
0
,
0
,
0
,
0
,
0
,
1
,
1
,
1
],
[
1
,
0
,
0
,
1
,
0
,
0
,
1
,
0
,
0
],
[
0
,
1
,
0
,
0
,
1
,
0
,
0
,
1
,
0
],
[
0
,
0
,
1
,
0
,
0
,
1
,
0
,
0
,
1
],
[
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
],
[
0
,
0
,
1
,
0
,
1
,
0
,
1
,
0
,
0
])
# Check to see if there are any wins
for
w
in
wins
:
S
=
sum
([
1
if
(
w
[
k
]
==
1
and
state
[
k
]
==
1
)
else
0
for
k
in
xrange
(
9
)])
if
S
==
3
:
# We have a win
return
True
# There were no wins so return False
return
False
def
isDraw
(
state
):
""""""
try
:
state
.
index
(
0
)
return
False
except
ValueError
:
return
True
except
:
raise
def
run
(
self
):
""""""
pass
if
__name__
==
"__main__"
:
P
,
R
=
TicTacToeMDP
().
run
()
ttt
=
mdp
.
ValueIteration
(
P
,
R
,
1
)
\ No newline at end of file
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