Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PyUNO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
Jakob Kirsch
PyUNO
Commits
60770f81
Commit
60770f81
authored
5 years ago
by
Jakob Kirsch
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit
parents
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
uno.py
+114
-0
114 additions, 0 deletions
uno.py
with
114 additions
and
0 deletions
uno.py
0 → 100644
+
114
−
0
View file @
60770f81
import
random
,
time
,
atexit
#definitions
DEBUG
=
True
COLOR_CODES
=
{
"
NEUTRAL
"
:
"
\033
[1;37;40m
"
,
"
BLUE
"
:
"
\033
[1;34;40m
"
,
"
GREEN
"
:
"
\033
[1;32;40m
"
,
"
RED
"
:
"
\033
[1;31;40m
"
,
"
YELLOW
"
:
"
\033
[1;33;40m
"
}
COLORS
=
(
"
BLUE
"
,
"
GREEN
"
,
"
RED
"
,
"
YELLOW
"
)
CARDS
=
[]
PLAYERS
=
[]
OVERFLOW
=
0
#for +2
WANTED_COLOR
=
"
NEUTRAL
"
#for C
def
clear
():
print
(
"
\033
[1;30;40m
"
+
"
\n
"
*
100
)
def
render_card
(
lis
):
return
COLOR_CODES
[
lis
[
1
]]
+
lis
[
0
]
def
print_card
(
lis
):
print
(
render_card
(
lis
))
def
print_stack
():
print_card
(
STACK
[::
-
1
][
0
])
def
compare_cards
(
card1
,
card2
):
global
OVERFLOW
,
WANTED_COLOR
if
card2
[
0
]
==
"
C
"
:
c
=
input
(
"
Color:
"
)
while
not
c
in
COLORS
:
c
=
input
(
"
Color:
"
)
WANTED_COLOR
=
c
card2
[
1
]
=
c
return
True
if
WANTED_COLOR
!=
"
NEUTRAL
"
:
ret
=
card2
[
1
]
==
WANTED_COLOR
if
ret
:
WANTED_COLOR
=
"
NEUTRAL
"
return
ret
if
card1
[
0
]
==
card2
[
0
]:
ret
=
True
elif
card1
[
1
]
==
card2
[
1
]:
ret
=
True
else
:
ret
=
False
if
ret
:
if
card2
[
0
]
==
"
+2
"
:
OVERFLOW
+=
2
else
:
OVERFLOW
=
0
return
ret
if
not
DEBUG
:
atexit
.
register
(
clear
)
#cards
for
color
in
COLORS
:
for
n
in
range
(
0
,
20
):
CARDS
.
append
((
str
(
n
%
10
),
color
))
for
n
in
range
(
0
,
2
):
CARDS
.
append
((
"
+2
"
,
color
))
CARDS
.
append
([
"
C
"
,
"
NEUTRAL
"
])
#players
p
=
input
(
"
Player:
"
)
while
p
!=
""
:
PLAYERS
.
append
(
p
)
p
=
input
(
"
Player:
"
)
#get cards
random
.
shuffle
(
CARDS
)
random
.
shuffle
(
PLAYERS
)
PCARDS
=
{}
for
player
in
PLAYERS
:
PCARDS
[
player
]
=
[]
for
n
in
range
(
0
,
7
):
PCARDS
[
player
].
append
(
CARDS
.
pop
())
clear
()
STACK
=
[
CARDS
.
pop
()]
#main
while
len
(
PLAYERS
)
>
1
:
for
player
in
PLAYERS
:
print_stack
()
input
(
"
\033
[1;30;40m
"
+
player
+
"
ist dran. Gib das Handy weiter und drücke Enter
"
)
print
(
"
0) Eine Karte ziehen
"
)
for
i
in
range
(
0
,
len
(
PCARDS
[
player
])):
print
(
"
{}) {}
\033
[1;30;40m
"
.
format
(
i
+
1
,
render_card
(
PCARDS
[
player
][
i
])))
card
=
-
1
while
card
<
0
or
card
>
len
(
PCARDS
[
player
]):
try
:
card
=
int
(
input
(
"
Card:
"
))
except
:
pass
if
card
>
0
and
card
<
len
(
PCARDS
[
player
]):
if
not
compare_cards
(
STACK
[::
-
1
][
0
],
PCARDS
[
player
][
card
-
1
]):
card
=
-
1
card
-=
1
#python starts at 0
if
PCARDS
[
player
][
card
][
0
]
!=
"
+2
"
and
OVERFLOW
>
0
:
print
(
"
\033
[1;30;40m
"
+
player
+
"
muss
"
+
str
(
OVERFLOW
)
+
"
Karten ziehen!
"
)
for
n
in
range
(
0
,
OVERFLOW
):
PCARDS
[
player
].
append
(
CARDS
.
pop
())
OVERFLOW
==
0
time
.
sleep
(
3
)
if
card
>
-
1
:
STACK
.
append
(
PCARDS
[
player
].
pop
(
card
))
else
:
PCARDS
[
player
].
append
(
CARDS
.
pop
())
clear
()
if
len
(
PCARDS
[
player
])
==
0
:
PCARDS
[
player
].
remove
(
player
)
print
(
"
\033
[1;30;40m
"
+
player
+
"
hat gewonnen!
"
)
time
.
sleep
(
1
)
\ No newline at end of file
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