Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AP-belkacemi-melissa
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
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Melissa Belkacemi
AP-belkacemi-melissa
Commits
32761ca5
Commit
32761ca5
authored
1 year ago
by
Belkacemi Melissa
Browse files
Options
Downloads
Patches
Plain Diff
card
parent
68cf7bde
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
TP8/bataille-carte/apqueue.py
+6
-1
6 additions, 1 deletion
TP8/bataille-carte/apqueue.py
TP8/bataille-carte/card.py
+32
-10
32 additions, 10 deletions
TP8/bataille-carte/card.py
TP8/bataille-carte/war.py
+9
-1
9 additions, 1 deletion
TP8/bataille-carte/war.py
with
47 additions
and
12 deletions
TP8/bataille-carte/apqueue.py
+
6
−
1
View file @
32761ca5
...
...
@@ -95,9 +95,14 @@ class ApQueue():
return the string representation of this queue.
"""
return
ApQueue
.
ARROW
+
\
"
|
"
.
join
(
str
(
el
)
for
el
in
self
.
__content
)
+
\
"
|
"
.
join
(
str
(
el
)
for
el
in
self
.
__content
[::
-
1
]
)
+
\
ApQueue
.
ARROW
def
__len__
(
self
)
->
int
:
"""
return the length of this queue
"""
return
len
(
self
.
__content
)
if
__name__
==
'
__main__
'
:
import
apl1test
...
...
This diff is collapsed.
Click to expand it.
TP8/bataille-carte/card
-squel
.py
→
TP8/bataille-carte/card.py
100644 → 100755
+
32
−
10
View file @
32761ca5
...
...
@@ -53,7 +53,8 @@ class Card(object):
précondition : value in VALUES and color in COLORS
"""
...
self
.
value
=
value
self
.
color
=
color
def
__hash__
(
self
)
->
int
:
...
...
@@ -69,7 +70,17 @@ class Card(object):
$$$ Card(
'
Ace
'
,
'
heart
'
)
Card(
"
Ace
"
,
"
heart
"
)
"""
...
return
f
'
Card(
"
{
self
.
value
}
"
,
"
{
self
.
color
}
"
)
'
def
__str__
(
self
)
->
str
:
"""
$$$ c=Card(
'
Ace
'
,
'
heart
'
)
$$$ repr(c)
'
Ace of heart
'
"""
return
f
'
{
self
.
value
}
of
{
self
.
color
}
'
def
compare
(
self
,
card
:
Card
)
->
int
:
"""
...
...
@@ -97,7 +108,13 @@ class Card(object):
$$$ c1.compare(c3) == 0
True
"""
...
if
Card
.
VALUES
.
index
(
self
.
value
)
<
Card
.
VALUES
.
index
(
card
.
value
):
res
=-
1
elif
Card
.
VALUES
.
index
(
self
.
value
)
>
Card
.
VALUES
.
index
(
card
.
value
):
res
=
1
else
:
res
=
0
return
res
@staticmethod
def
deck
(
n_card
:
int
)
->
list
[
Card
]:
...
...
@@ -116,49 +133,54 @@ class Card(object):
$$$ len(set(cartes))
len(cartes)
"""
...
cartes
=
[
Card
(
Card
.
VALUES
[
i
],
Card
.
COLORS
[
j
])
for
i
in
range
(
len
(
Card
.
VALUES
))
for
j
in
range
(
len
(
Card
.
COLORS
))]
random
.
shuffle
(
cartes
)
res
=
[]
for
i
in
range
(
n_card
):
res
.
append
(
cartes
[
i
])
return
res
def
__eq__
(
self
,
card
:
Card
)
->
bool
:
"""
return True if self equals card
False otherwise
"""
...
return
self
.
compare
(
card
)
==
0
def
__neq__
(
self
,
card
:
Card
)
->
bool
:
"""
return True if self don
'
t equal card
False otherwise
"""
...
return
self
.
compare
(
card
)
!=
0
def
__lt__
(
self
,
card
:
Card
)
->
bool
:
"""
return True if self is strictly inferior to card
False otherwise
"""
...
return
self
.
compare
(
card
)
<
0
def
__le__
(
self
,
card
:
Card
)
->
bool
:
"""
return True if self is inferior or equal to card
False otherwise
"""
...
return
self
.
compare
(
card
)
<=
0
def
__gt__
(
self
,
card
:
Card
)
->
bool
:
"""
return True if self is strictly superior to card
False otherwise
"""
...
return
self
.
compare
(
card
)
>
0
def
__ge__
(
self
,
card
:
Card
)
->
bool
:
"""
return True if self is superior or equal to card
False otherwise
"""
...
return
self
.
compare
(
card
)
>=
0
if
(
__name__
==
'
__main__
'
):
...
...
This diff is collapsed.
Click to expand it.
TP8/bataille-carte/war
-squel
.py
→
TP8/bataille-carte/war.py
100644 → 100755
+
9
−
1
View file @
32761ca5
...
...
@@ -37,7 +37,15 @@ def distribute(n_card: int) -> tuple[ApQueue, ApQueue]:
$$$ isinstance(carte, Card)
True
"""
...
m1
=
ApQueue
()
m2
=
ApQueue
()
cartes
=
deck
(
2
*
n_card
)
for
i
in
range
(
n
):
m1
.
enqueue
(
cartes
[
i
])
m2
.
enqueue
(
cartes
[
2
*
n
-
i
])
return
(
m1
,
m2
)
def
gather_stack
(
main
:
ApQueue
,
pile
:
ApStack
)
->
None
:
"""
...
...
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