Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
TicTacToe-Robot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lukas Hoffleit
TicTacToe-Robot
Commits
06dd6b28
Commit
06dd6b28
authored
1 month ago
by
Lukas Hoffleit
Browse files
Options
Downloads
Patches
Plain Diff
Falsche datei
parent
410ad891
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
TicTacToe.py
+0
-58
0 additions, 58 deletions
TicTacToe.py
with
0 additions
and
58 deletions
TicTacToe.py
deleted
100644 → 0
+
0
−
58
View file @
410ad891
from
enum
import
Enum
class
Player
(
Enum
):
one
=
1
two
=
2
undefined
=
3
class
TicTacToe
():
def
__init__
(
self
)
->
None
:
self
.
grid
=
[]
for
i
in
range
(
3
):
self
.
grid
.
append
([
Player
.
undefined
,
Player
.
undefined
,
Player
.
undefined
])
def
add
(
self
,
row
,
col
,
player
)
->
bool
:
"""
Change the value of a undefined field.
The player can be passed as Player Object or plain Int.
Returns True, if executed correctly.
Returns False, if the field is already occupied
or the player number is invalid.
"""
if
isinstance
(
player
,
int
):
try
:
player
=
Player
(
player
)
except
ValueError
:
return
False
# invalid player number
if
self
.
check_field
(
row
,
col
):
self
.
grid
[
row
][
col
]
=
player
return
True
return
False
def
check_field
(
self
,
row
,
col
)
->
bool
:
"""
Checks, if a field is occupied
"""
if
self
.
grid
[
row
][
col
]
!=
Player
.
undefined
:
return
False
return
True
def
print_grid
(
self
)
->
None
:
symbols
=
{
Player
.
one
:
"
X
"
,
Player
.
two
:
"
O
"
,
Player
.
undefined
:
"
"
}
print
(
"
┌───┬───┬───┐
"
)
for
i
,
row
in
enumerate
(
self
.
grid
):
print
(
"
│
"
,
end
=
""
)
for
field
in
row
:
print
(
f
"
{
symbols
[
field
]
}
│
"
,
end
=
""
)
if
i
<
len
(
self
.
grid
)
-
1
:
print
(
"
\n
├───┼───┼───┤
"
)
print
(
"
\n
└───┴───┴───┘
\n
"
)
if
__name__
==
"
__main__
"
:
ttt
=
TicTacToe
()
ttt
.
add
(
1
,
1
,
1
)
ttt
.
print_grid
()
ttt
.
add
(
1
,
2
,
Player
.
two
)
ttt
.
print_grid
()
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