Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AP
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Koffi Gantchou
AP
Commits
a69b8be8
Commit
a69b8be8
authored
3 months ago
by
Koffi Gantchou
Browse files
Options
Downloads
Patches
Plain Diff
tp bataille carte
parent
ac94b622
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
bataille-carte/apqueue.py
+20
-0
20 additions, 0 deletions
bataille-carte/apqueue.py
bataille-carte/card.py
+6
-6
6 additions, 6 deletions
bataille-carte/card.py
bataille-carte/war.py
+52
-4
52 additions, 4 deletions
bataille-carte/war.py
with
78 additions
and
10 deletions
bataille-carte/apqueue.py
+
20
−
0
View file @
a69b8be8
#!/usr/bin/python3
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
"""
"""
:mod:`apqueue` module
:mod:`apqueue` module
...
@@ -57,6 +58,7 @@ class ApQueue():
...
@@ -57,6 +58,7 @@ class ApQueue():
def
__init__
(
self
):
def
__init__
(
self
):
"""
"""
build a new empty queue
build a new empty queue
precondition: none
precondition: none
"""
"""
...
@@ -107,3 +109,21 @@ class ApQueue():
...
@@ -107,3 +109,21 @@ class ApQueue():
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
import
apl1test
import
apl1test
apl1test
.
testmod
(
'
apqueue.py
'
)
apl1test
.
testmod
(
'
apqueue.py
'
)
# import unittest
# class TestMathFunctions(unittest.TestCase):
# """ à_remplacer_par_ce_que_fait_la_classe
#
# Exemple(s) :
# $$$
# """
# def test___str__(self):
# """ à_remplacer_par_ce_que_fait_la_fonction
#
# Précondition :
# Exemple(s) :
# $$$
# """
# self.assertEqual(__str__(self),)
#
This diff is collapsed.
Click to expand it.
bataille-carte/card.py
+
6
−
6
View file @
a69b8be8
...
@@ -148,42 +148,42 @@ class Card(object):
...
@@ -148,42 +148,42 @@ class Card(object):
return True if self equals card
return True if self equals card
False otherwise
False otherwise
"""
"""
return
card
.
compare
(
card
)
==
0
return
self
.
compare
(
card
)
==
0
def
__neq__
(
self
,
card
:
Card
)
->
bool
:
def
__neq__
(
self
,
card
:
Card
)
->
bool
:
"""
"""
return True if self don
'
t equal card
return True if self don
'
t equal card
False otherwise
False otherwise
"""
"""
return
card
.
compare
(
card
)
!=
0
return
self
.
compare
(
card
)
!=
0
def
__lt__
(
self
,
card
:
Card
)
->
bool
:
def
__lt__
(
self
,
card
:
Card
)
->
bool
:
"""
"""
return True if self is strictly inferior to card
return True if self is strictly inferior to card
False otherwise
False otherwise
"""
"""
return
card
.
compare
(
card
)
==-
1
return
self
.
compare
(
card
)
==-
1
def
__le__
(
self
,
card
:
Card
)
->
bool
:
def
__le__
(
self
,
card
:
Card
)
->
bool
:
"""
"""
return True if self is inferior or equal to card
return True if self is inferior or equal to card
False otherwise
False otherwise
"""
"""
return
card
.
compare
(
card
)
<=
0
return
self
.
compare
(
card
)
<=
0
def
__gt__
(
self
,
card
:
Card
)
->
bool
:
def
__gt__
(
self
,
card
:
Card
)
->
bool
:
"""
"""
return True if self is strictly superior to card
return True if self is strictly superior to card
False otherwise
False otherwise
"""
"""
return
card
.
compare
(
card
)
==
1
return
self
.
compare
(
card
)
==
1
def
__ge__
(
self
,
card
:
Card
)
->
bool
:
def
__ge__
(
self
,
card
:
Card
)
->
bool
:
"""
"""
return True if self is superior or equal to card
return True if self is superior or equal to card
False otherwise
False otherwise
"""
"""
return
card
.
compare
(
card
)
>=
0
return
self
.
compare
(
card
)
>=
0
if
(
__name__
==
'
__main__
'
):
if
(
__name__
==
'
__main__
'
):
...
...
This diff is collapsed.
Click to expand it.
bataille-carte/war.py
+
52
−
4
View file @
a69b8be8
...
@@ -16,6 +16,7 @@ from apqueue import *
...
@@ -16,6 +16,7 @@ from apqueue import *
from
apstack
import
*
from
apstack
import
*
def
distribute
(
n_card
:
int
)
->
tuple
[
ApQueue
,
ApQueue
]:
def
distribute
(
n_card
:
int
)
->
tuple
[
ApQueue
,
ApQueue
]:
"""
"""
renvoie un couple (m1, m2) constitué de deux files,
renvoie un couple (m1, m2) constitué de deux files,
...
@@ -85,7 +86,36 @@ def play_one_round(m1: ApQueue, m2: ApQueue, pile: ApStack) -> None:
...
@@ -85,7 +86,36 @@ def play_one_round(m1: ApQueue, m2: ApQueue, pile: ApStack) -> None:
pile.
pile.
precondition : m1 et m2 ne sont pas vides
precondition : m1 et m2 ne sont pas vides
$$$ m1 = ApQueue()
$$$ m2 = ApQueue()
$$$ pile = ApStack()
$$$ c1 = Card(
'
Ace
'
,
'
heart
'
)
$$$ c2 = Card(
'
King
'
,
'
heart
'
)
$$$ m1.enqueue(c1)
$$$ m2.enqueue(c1)
$$$ m1.enqueue(c2)
$$$ len(m1) == 2
True
$$$ play_one_round(m1,m2,pile)
$$$ len(pile) == 2
True
"""
"""
m1_carte1
=
m1
.
dequeue
()
m2_carte2
=
m2
.
dequeue
()
print
(
f
"
le joueur 1 a
{
m1_carte1
}
et le joueur2 a
{
m2_carte2
}
"
)
pile
.
push
(
m2_carte2
)
pile
.
push
(
m1_carte1
)
if
m1_carte1
>
m2_carte2
:
gather_stack
(
m1
,
pile
)
print
(
'
joueur1 gagne
'
)
elif
m1_carte1
<
m2_carte2
:
gather_stack
(
m2
,
pile
)
print
(
'
joueur2 gagne
'
)
else
:
print
(
'
bataille
'
)
def
play
(
n_card
:
int
,
n_round
:
int
)
->
None
:
def
play
(
n_card
:
int
,
n_round
:
int
)
->
None
:
...
@@ -95,10 +125,28 @@ def play(n_card: int, n_round: int) -> None:
...
@@ -95,10 +125,28 @@ def play(n_card: int, n_round: int) -> None:
n_card: le nombre de cartes à distribuer à chaque joueur.
n_card: le nombre de cartes à distribuer à chaque joueur.
n_round: le nombre maximal de tours
n_round: le nombre maximal de tours
"""
"""
...
i
=
0
j1
,
j2
=
distribute
(
n_card
)
pile
=
ApStack
()
while
i
<
n_round
and
not
(
len
(
j1
)
==
0
or
len
(
j2
)
==
0
):
play_one_round
(
j1
,
j2
,
pile
)
print
(
f
"
le joueur1 a
{
len
(
j1
)
}
cartes et le joueur2 a
{
len
(
j2
)
}
cartes
"
)
i
+=
1
if
len
(
j1
)
==
0
:
print
(
'
joueur2 a gagné
'
)
elif
len
(
j2
)
==
0
:
print
(
'
joueur1 a gagné
'
)
if
__name__
==
"
__main__
"
:
play
(
4
,
10
)
#import apl1test
#apl1test.testmod("war.py")
if
__name__
==
"
__main__
"
:
import
apl1test
apl1test
.
testmod
(
"
war.py
"
)
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