MCPcopy Create free account
hub / github.com/ActiveState/code / think

Method think

recipes/Python/580811_Uno_TextBased/recipe-580811.py:408–480  ·  view source on GitHub ↗
(self, match)

Source from the content-addressed store, hash-verified

406 raise ValueError("Card Cannot Be Found")
407
408 def think(self, match):
409 card = None
410 self.currentColor = match.currentColor
411 currentValue = match.currentValue
412 zeroChangeRule = match.zeroChange
413 twoPlayers = False
414 previousTurnID = match.getNextTurn(True)
415 nextTurnID = match.getNextTurn(False)
416 previousPlayer = match.getPlayer(previousTurnID)
417 #nextPlayer = match.getPlayer(nextTurnID)
418 if previousTurnID == nextTurnID:
419 twoPlayers = True
420 if self.canSkip == False and self.canReverse == True:
421 self.canSkip = True
422 self.canReverse = False
423
424 self.getLegalCards(self.currentColor, currentValue, zeroChangeRule)
425
426 ### DRAW CASE ###
427
428 if len(self.legalCards) == 0 and len(self.wildCards) == 0:
429 return "d"
430
431 else:
432
433 ### NO LEGAL CARD, USE WILD CARD ###
434
435 if len(self.legalCards) == 0:
436
437 if zeroChangeRule and self.canZeroChange:
438 bestZeroColor = self.getBestColor(self.zeroCards)
439 card = self.getCardByColor(self.zeroCards, bestZeroColor)
440
441 else:
442
443 if self.canDrawFour:
444 card = self.getCardByValue(self.wildCards, "+4")
445 print(card)
446
447 else:
448 card = random.choice(self.wildCards)
449
450 else:
451
452 ### HAS LEGAL CARD ###
453
454 if twoPlayers and self.canSkip: #Always play a skip card in a two player game
455 #print("Shed Skip Strategy")
456 card = self.getCardByValue(self.legalCards,"R", "X")
457
458 if self.canReverse and previousPlayer.didDraw():
459 #print("Reverse Strategy")
460 reverseCards = self.getAllCardsByValue(self.legalCards, "R")
461 for reverseCard in reverseCards:
462 if reverseCard.getColor() == self.currentColor:
463 card = reverseCard
464
465 if self.canValueChange:

Callers 1

nextTurnMethod · 0.45

Calls 15

getBestColorMethod · 0.95
getCardByColorMethod · 0.95
getCardByValueMethod · 0.95
getAllCardsByValueMethod · 0.95
indexCardMethod · 0.95
printFunction · 0.85
listClass · 0.85
strFunction · 0.85
getNextTurnMethod · 0.80
getPlayerMethod · 0.80
getLegalCardsMethod · 0.80
didDrawMethod · 0.80

Tested by

no test coverage detected