Skip to content

Commit

Permalink
LE MINMAXBOT SUPER TROP COOL TROP FORT
Browse files Browse the repository at this point in the history
  • Loading branch information
Warglabidoo committed Apr 23, 2024
1 parent 4e3bae4 commit d2ba25f
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions 6QuiPrend/players/minMaxBot.py
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

0 comments on commit d2ba25f

Please sign in to comment.