-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LE MINMAXBOT SUPER TROP COOL TROP FORT
- Loading branch information
1 parent
4e3bae4
commit d2ba25f
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from random import randint | ||
from players.bot import Bot | ||
from game.card import Card | ||
|
||
class MinMaxBot(Bot): | ||
|
||
def update_table(self, table, cards, myCard): | ||
""" | ||
Met à jour le plateau après un tour de jeu. | ||
:param plays: Les coups joués pendant le tour, un coup est un couple (joueur, carte jouée). | ||
""" | ||
monScore=0 | ||
for card in cards: | ||
placed = False | ||
for i in range(len(table) - 1, -1, -1): | ||
if table[i][-1]<card: | ||
if len(table[i]) < 5: | ||
table[i].append(card) | ||
else: | ||
cows = sum(card.cowsNb for card in table[i]) | ||
if card==myCard: | ||
monScore+= cows | ||
table[i] = [card] | ||
table.sort(key=lambda x: x[-1]) | ||
placed = True | ||
break | ||
if not placed: | ||
|
||
line=1 | ||
|
||
cows = sum(card.cowsNb for card in table[line-1]) | ||
if card==myCard: | ||
monScore+= cows | ||
table[line - 1] = [card] | ||
table.sort(key=lambda x: x[-1]) | ||
return monScore | ||
|
||
def parcours(self, baseHand, basePlayedCards, baseTable , iterationsLeft): | ||
min=1000 | ||
minCard=baseHand[0] | ||
for myCard in baseHand: | ||
max=0 | ||
for enemyCard in [Card(c) for c in range(1,105) if (Card(c) not in basePlayedCards) and (Card(c) not in baseHand)]: | ||
tempTable=[[carte for carte in ligne] for ligne in baseTable] | ||
monScore=self.update_table(tempTable, [myCard, enemyCard], myCard) | ||
if len(baseHand)!=1 and iterationsLeft!=0: | ||
monScore+=self.parcours([c for c in baseHand if c!=myCard],[c for c in basePlayedCards if c!=myCard and c!=enemyCard], tempTable, iterationsLeft-1)[0] | ||
if monScore>max: | ||
max=monScore | ||
if max<min: | ||
min=max | ||
minCard=myCard | ||
return [min,minCard] | ||
|
||
|
||
def getLineToRemove(self, game): | ||
return randint(1, 4) | ||
|
||
def getCardToPlay(self, game): | ||
profondeur = 1 | ||
retour = self.parcours(self.hand, game.alreadyPlayedCards, game.table, profondeur) | ||
return retour[1].value |