Welcome, guest | Sign In | My Account | Store | Cart
```from random import randint, seed
from time import time

def game():
print 'Welcome to WAR V2!'
print
try:
players = int(raw_input('How many players are there? '))
if players < 2:
print 'There must be at least two players.'
else:
except:
print 'You must enter a number.'
print
names = []
for name in range(players):
names.append(raw_input('What is the name of player ' + str(name + 1) + '? '))
deck = []
for card in range(10):
for player in range(players):
deck.append(card)
hands = []
seed(time())
for player in range(players):
hand = ([], [])
for card in range(10):
index = randint(0, len(deck) - 1)
hand.append(deck[index])
del deck[index]
hands.append(hand)
for round in range(1, 11):
table = []
will_play = []
high_card = 0
for player in range(players):
will_play.append(player)
for turn in range(players):
for line in range(50):
print
index = randint(0, len(will_play) - 1)
now_play = will_play[index]
del will_play[index]
print 'Round', round
raw_input('It is ' + names[now_play] + "'s turn to play.")
print
if len(table) == 0:
print 'There are no cards on the table.'
else:
for card in range(len(table)):
print names[table[card]] + ' played a ' + str(table[card]) + '.'
print
print 'These are your playing cards: ' + str(hands[now_play])[1:-1] + '.'
if len(hands[now_play]) > 0:
print 'These are your captured cards: ' + str(hands[now_play])[1:-1] + '.'
print
try:
card = int(raw_input('What card do you want to play? '))
if card >= 0 and card <= 9:
try:
hands[now_play].remove(card)
table.append((now_play, card))
if card > high_card:
high_card = card
except:
print 'You do not have that card.'
else:
print 'You must enter a value between -1 and 10.'
except:
print 'You must enter a number.'
for line in range(50):
print
for card in range(players):
print names[table[card]] + ' played a ' + str(table[card]) + '.'
hand_out = []
for index in range(players):
if table[index] == high_card:
hand_out.append(table[index])
while len(table) > 0:
hands[hand_out[randint(0, len(hand_out) - 1)]].append(table)
del table
print
for player in range(players):
if len(hands[player]) > 0:
print names[player] + ' has captured ' + str(len(hands[player])) + ' cards.'
print
raw_input('End Of Round ' + str(round))
for line in range(50):
print
high_score = 0
scores = []
for player in range(players):
total = 0
for card in range(len(hands[player])):
total += hands[player][card]
if total > high_score:
high_score = total
if len(scores) == 0 or scores[len(scores) - 1] <= total:
scores.append((player, total))
else:
for index in range(scores):
if total > scores[index]:
scores.insert((player, total))
break
for player in range(players):
print names[scores[player]] + ' received ' + str(scores[player]) + ' points.'
print
raw_input('GAME OVER')

if __name__ == '__main__':
game()
```