added ability to choose difficulty
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
|
|
||||||
from deck import deck
|
from deck import deck
|
||||||
#from card import card
|
|
||||||
from player import BotPlayer, HumanPlayer
|
from player import BotPlayer, HumanPlayer
|
||||||
from rules import Rule, RuleEngine
|
from rules import RuleEngine
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@@ -11,25 +10,25 @@ deck.shuffle()
|
|||||||
#deck.show()
|
#deck.show()
|
||||||
deck.first_card()
|
deck.first_card()
|
||||||
|
|
||||||
player_count = int(input('How many players do you want to play with? '))
|
|
||||||
players = []
|
players = []
|
||||||
for i in range(player_count):
|
player_count = int(input('How many human players? '))
|
||||||
player_name = input(f'Enter the name of player {i+1}: ')
|
if player_count > 0:
|
||||||
players.append(HumanPlayer(player_name))
|
for i in range(player_count):
|
||||||
print(f'player {player_name} has been added')
|
player_name = input(f'Enter the name of player {i+1}: ')
|
||||||
|
players.append(HumanPlayer(player_name))
|
||||||
|
print(f'player {player_name} has been added')
|
||||||
|
|
||||||
|
difficulty = input('What difficulty do you want the bots to be? (easy, medium, hard) ')
|
||||||
|
if difficulty not in ['easy', 'medium', 'hard']:
|
||||||
|
difficulty = 'medium'
|
||||||
bot_count = int(input('How many bots do you want to play against? '))
|
bot_count = int(input('How many bots do you want to play against? '))
|
||||||
bots = []
|
bots = []
|
||||||
for i in range(bot_count):
|
for i in range(bot_count):
|
||||||
bots.append(f'bot{i+1}')
|
bots.append(f'bot{i+1}')
|
||||||
|
|
||||||
players = []
|
|
||||||
# In your main game loop
|
|
||||||
players = [HumanPlayer('Jake')] # Add other players
|
|
||||||
|
|
||||||
# Create player objects
|
# Create player objects
|
||||||
for person in bots:
|
for person in bots:
|
||||||
game_player = BotPlayer(person)
|
game_player = BotPlayer(person, difficulty)
|
||||||
players.append(game_player)
|
players.append(game_player)
|
||||||
|
|
||||||
# Now you can use your player objects
|
# Now you can use your player objects
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import json
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
|
|
||||||
error_chance = 0.3
|
|
||||||
|
|
||||||
class player:
|
class player:
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
@@ -24,14 +23,21 @@ class player:
|
|||||||
return len(self.hand)
|
return len(self.hand)
|
||||||
|
|
||||||
class BotPlayer(player):
|
class BotPlayer(player):
|
||||||
def __init__(self, name):
|
def __init__(self, name, difficulty='medium'):
|
||||||
super().__init__(name)
|
super().__init__(name)
|
||||||
|
self.difficulty = difficulty
|
||||||
|
if self.difficulty == 'easy':
|
||||||
|
self.error_chance = 0.4
|
||||||
|
elif self.difficulty == 'hard':
|
||||||
|
self.error_chance = 0.2
|
||||||
|
else:
|
||||||
|
self.error_chance = 0.3
|
||||||
|
|
||||||
def command(self, card):
|
def command(self, card):
|
||||||
rules = json.load(open('rules.json'))
|
rules = json.load(open('rules.json'))
|
||||||
commands = []
|
commands = []
|
||||||
#chance to return the wrong command
|
#chance to return the wrong command
|
||||||
if random.random() < error_chance:
|
if random.random() < self.error_chance:
|
||||||
commands.append('wrong command')
|
commands.append('wrong command')
|
||||||
#print(f'generating command for {len(self.hand)} cards, {card.suit} and {card.value}')
|
#print(f'generating command for {len(self.hand)} cards, {card.suit} and {card.value}')
|
||||||
for rule in rules:
|
for rule in rules:
|
||||||
|
|||||||
Reference in New Issue
Block a user