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
1750cc72
Commit
1750cc72
authored
2 months ago
by
Lukas Hoffleit
Browse files
Options
Downloads
Patches
Plain Diff
Spielfeld in Farben
parent
90c9b6b9
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tictactoe.py
+19
-11
19 additions, 11 deletions
tictactoe.py
with
19 additions
and
11 deletions
tictactoe.py
+
19
−
11
View file @
1750cc72
...
...
@@ -7,13 +7,25 @@ class Player(Enum):
two
=
2
grid_full
=
3
# Adjust the symbol or color for printing the grid
SYMBOLS
=
{
Player
.
one
:
"
X
"
,
Player
.
two
:
"
O
"
,
Player
.
undefined
:
"
"
}
COLORS
=
{
Player
.
one
:
"
\033
[32m
"
,
# green
Player
.
two
:
"
\033
[94m
"
,
# blue
Player
.
undefined
:
""
}
END_COLOR
=
"
\033
[0m
"
def
get_opponent
(
player
:
Player
)
->
Player
:
if
player
==
Player
.
one
:
return
Player
.
two
else
:
return
Player
.
one
class
TicTacToeError
(
Exception
):
"""
TicTacToe Error
"""
...
...
@@ -37,7 +49,8 @@ class TicTacToe():
return
player
def
add
(
self
,
row
:
int
,
col
:
int
,
player
:
Player
|
int
,
grid
:
np
.
ndarray
|
None
=
None
)
->
bool
:
"""
Change the value of a undefined field.
"""
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
...
...
@@ -52,7 +65,9 @@ class TicTacToe():
return
False
def
check_field
(
self
,
row
:
int
,
col
:
int
,
grid
:
np
.
ndarray
|
None
=
None
)
->
bool
:
"""
Checks, if a field is occupied
"""
"""
Checks, if a field is occupied
"""
if
grid
is
None
:
grid
=
self
.
grid
if
self
.
grid
[
row
][
col
]
!=
Player
.
undefined
:
...
...
@@ -66,17 +81,12 @@ class TicTacToe():
"""
if
grid
is
None
:
grid
=
self
.
grid
symbols
=
{
Player
.
one
:
"
X
"
,
Player
.
two
:
"
O
"
,
Player
.
undefined
:
"
"
}
print
(
"
\t
┌───┬───┬───┐
"
)
for
i
,
row
in
enumerate
(
grid
):
print
(
"
\t
│
"
,
end
=
""
)
for
field
in
row
:
print
(
f
"
{
symbols
[
field
]
}
│
"
,
end
=
""
)
print
(
f
"
{
COLORS
[
field
]
}{
SYMBOLS
[
field
]
}{
END_COLOR
}
│
"
,
end
=
""
)
if
i
<
len
(
grid
)
-
1
:
print
(
"
\n\t
├───┼───┼───┤
"
)
print
(
"
\n\t
└───┴───┴───┘
\n\n
"
)
...
...
@@ -192,5 +202,3 @@ if __name__ == "__main__":
else
:
current_player
=
Player
.
one
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