Nu kan du spille kortspillet Krig – online!

https://wallnot.dk/krig/ har jeg netop offentliggjort årets julespil nummer 1: Krig!

Ej, jeg havde allerede prøvet at simulere Krig, men synes det kunne være spændende at få logikkerne til at hænge sammen med interaktivitet (dog højst begrænset) og logikker for rent faktisk at vise spillet.

Nu har jeg gjort et forsøg og jeg har kommenteret en masse i koden, så den forhåbentlig er nem at følge med i.

Her er views.py fra Django:

from django.shortcuts import render
import random			# Used to shuffle decks
import base64			# Used for obfuscation and deobfuscation functions
from math import ceil 	# Used to round up

# Create decks function - not a view
def new_deck(context):
	# Create card values and list of cards in each colour
	card_values = range(2,15)
	spades = [str(i) + "S" for i in card_values]
	clubs = [str(i) + "C" for i in card_values]
	diamonds = [str(i) + "D" for i in card_values]
	hearts = [str(i) + "H" for i in card_values]
	# Combine colours to deck
	deck = spades + clubs + diamonds + hearts
	# Shuffle deck		
	random.shuffle(deck)
	# Divide deck between two players and convert to commaseparated string
	player_a_deck = ",".join(deck[0:26])
	player_b_deck = ",".join(deck[26:52])
	# Obfuscate decks to make cheating marginally harder using the obfuscate function
	# production variable toggles this behavior because it's very time consuming to debug
	# if obfuscation is on
	production = True
	if production == True:
		player_a_deck = obfuscate(player_a_deck)
		player_b_deck = obfuscate(player_b_deck)
	# Add the two decks to context
	context['player_a_deck_form'] = player_a_deck
	context['player_b_deck_form'] = player_b_deck
	# Set index to 0 to only turn one card for first round of game
	context['index'] = 0
	return context

# Obfuscate by converting to base64 encoding - not a view
def obfuscate(deck):
	return base64.b64encode(deck.encode()).decode()

# Deobfuscate by converting from base64 encoding to string - not a view
def deobfuscate(deck):
	return base64.b64decode(deck.encode()).decode()

# Logic to create a list of which cards should be hidden or shown to player - not a view
def show_hide_cards(cards_on_table, index):
	counter = 0
	cards_on_table_show_hide = []
	for card in cards_on_table:
		# First card should always be shown
		if counter == 0:
			cards_on_table_show_hide.append([card, True])
		# If the card number is divisible by 4 it is the turn card in a war
		elif counter % 4 == 0:
			cards_on_table_show_hide.append([card, True])
		# If the card number equals the index value, one or both players does not
		# have enough cards for a full war so the last card should be turned
		elif counter == index:
			cards_on_table_show_hide.append([card, True])
		else:
			cards_on_table_show_hide.append([card, False])
		counter += 1
	return cards_on_table_show_hide

# Page view
def index(request):
	# Empty context variable to add to
	context = {}
	# Production variable to toggle obfuscation
	production = True
	# First visit, game has not been started
	if not request.method == 'POST':
		# Create a deck using the new_deck function
		new_deck(context)
	# Game has started
	else:
		### GAME PREPARATION AND CARD DISPLAY LOGIC ###
		# Current game status is used in template to know whether game has been
		# started or not, or has ended
		game_status = "Going on"
		
		# Get submitted decks from user submitted POST request
		player_a_deck = request.POST.get('player_a_deck')
		player_b_deck = request.POST.get('player_b_deck')
		
		# Deobfuscate submitted decks using the deobfuscate function
		if production == True:
			player_a_deck = deobfuscate(player_a_deck)
			player_b_deck = deobfuscate(player_b_deck)
		
		# Convert decks to lists
		player_a_deck = player_a_deck.split(",")
		player_b_deck = player_b_deck.split(",")

		# Get submitted index value in order to know which cards to compare
		# The index is used in case of war to determine which cards to compare
		# and what cards to show to player
		index = int(request.POST.get('index'))
		context['current_index'] = index
		
		# In order to display cards in correct order in case of war for player_b
		# a number of slices are prepared and added to context as strings in a list.
		# number_of_slices is rounded up in case index is not divisible by 4 (endgame logic)
		number_of_slices = ceil(index/4)	
		slices = []
		# Only needed if number of slices is above 0
		if number_of_slices:
			start = 1
			end = 5
			for slice in range(number_of_slices):
				slices.append(str(start)+":"+str(end))
				start +=4
				end += 4
		context['slices'] = slices
		
		# In order to display cards to player using a loop, the deck is sliced
		# by the index value plus 1. # If index is 0, 1 card should be shown.
		# If index is 4 because of war, 5 cards should be shown... and so on.
		a_cards_on_table = player_a_deck[:index+1]
		b_cards_on_table = player_b_deck[:index+1]
		
		# Cards on table is run through function to decide which cards to show face up/face down
		# to player and added to context.
		context['a_cards_on_table'] = show_hide_cards(a_cards_on_table, index)
		context['b_cards_on_table'] = show_hide_cards(b_cards_on_table, index)
		
		# Length of cards "on the table" is calculated in order to calculate remaining cards in player decks.
		# The value for player a is shown to the players and is also used for template card display logic.
		a_cards_on_table_length = len(a_cards_on_table)
		b_cards_on_table_length = len(b_cards_on_table)
				
		# Calculate number of cards in decks
		a_number_of_cards = len(player_a_deck)
		b_number_of_cards = len(player_b_deck)

		# Add remaining cards in deck to context to show to players
		a_remaining_in_deck = a_number_of_cards - a_cards_on_table_length
		b_remaining_in_deck = b_number_of_cards - b_cards_on_table_length
		context['a_remaining_in_deck'] = a_remaining_in_deck
		context['b_remaining_in_deck'] = b_remaining_in_deck
		
		### GAME LOGIC ###
		# Check if both players have decks large enough to compare
		if a_number_of_cards > index and b_number_of_cards > index:
			# Convert first card in decks to integer value in order to compare
			player_a_card = int(player_a_deck[index][:len(player_a_deck[index])-1])
			player_b_card = int(player_b_deck[index][:len(player_b_deck[index])-1])

			# Player a has the largest card
			if player_a_card > player_b_card:
				# Add cards in play to end of player a deck and delete them from beginning
				# of player a and player b decks
				player_a_deck.extend(player_a_deck[:index+1])
				player_a_deck.extend(player_b_deck[:index+1])	
				del player_a_deck[:index+1]
				del player_b_deck[:index+1]
				# If a play is decided, index is set to 0
				index = 0
				context['message'] = "Du vandt runden!"
			# Player b has the largest card
			elif player_a_card < player_b_card:
				# Cards are added to deck in different order from player a to deck in order
				# to avoid game risk of going on forever
				player_b_deck.extend(player_b_deck[:index+1])	
				player_b_deck.extend(player_a_deck[:index+1])
				del player_a_deck[:index+1]
				del player_b_deck[:index+1]
				# If a play is decided, index is set to 0
				index = 0
				context['message'] = "Du tabte runden!"
			# Cards must be equal and war is on
			else:
				# In case of war normally four cards are added to the index, but
				# In order to accomodate a case of end-game war, there are special cases
				# if either player doesn't quite have enough cards for a full 4-card-turn war
				if a_number_of_cards >= index + 4 <= b_number_of_cards:
					index += 4
				# Since the if statement two levels up already checks that number of cards is larger
				# than the index value, an else with no criteria is enough to decide how many cards
				# each player has left to turn and add the smallest number to the index
				else:
					# Calculate the difference between number of cards and index for each player.
					# The smallest of the two differences is added to index to decide how many cards to use for war.
					# One is subtracted for the card already on the table
					a_difference = a_number_of_cards - index
					b_difference = b_number_of_cards - index
					index += min(a_difference, b_difference) - 1
					# Edge case: If war on last remaining card for either player, 1 is added to index to end the game
					# by getting the index above the number of cards in the deck of the player(s) with no cards left
					if a_remaining_in_deck == 0 or b_remaining_in_deck == 0:
						index += 1
				# Messages are different for single, double, trippel wars and anything above.
				# Since the index can be upped by less than four, less than or equal is used to
				# decide which kind of war is on.
				if index <= 4:
					context['message'] = "Krig!"
				elif index <= 8:
					context['message'] = "Dobbeltkrig!"
				elif index <= 12:
					context['message'] = "Trippelkrig!"
				else:
					context['message'] = "Multikrig!"
		
		### AFTER GAME LOGIC AND DECIDE GAME LOGIC ###
		# Calculate length of decks after game logic has run
		player_a_deck_length = len(player_a_deck)
		player_b_deck_length = len(player_b_deck)
		
		# Compare lengths of decks to decide if someone has won. The number of cards on table for
		# next turn of cards is always at least one more than the index (index 0, 1 card, index 4,
		# 5 cards). There are three possible outcomes:
		# 1) Equal game: Both players are unable to turn and have equal sized decks (very, very rare!)
		# 2) Player a is unable to play and has a smaller deck than b (if both players are unable to turn, largest deck wins)
		# 3) Same as 2) for player b
		if player_a_deck_length <= index and player_b_deck_length <= index and player_a_deck_length == player_b_deck_length:
			context['message'] = "Spillet blev uafgjort. Hvor tit sker det lige?"
			game_status = "Over"
		elif player_a_deck_length <= index and player_a_deck_length < player_b_deck_length:
			context['message'] = "Du tabte spillet!"
			game_status = "Over"			
		elif player_b_deck_length <= index and player_b_deck_length < player_a_deck_length:
			context['message'] = "Du vandt spillet!"	
			game_status = "Over"			

		# Add size of decks after play to context to decide whether to show decks to player
		context['after_deck_a'] = player_a_deck
		context['after_deck_b'] = player_b_deck
		
		# Add game status to context
		context['game_status'] = game_status
		
		# Convert decks back to strings
		player_a_deck = ",".join(player_a_deck)
		player_b_deck = ",".join(player_b_deck)
		
		# Obfuscate decks using obfuscate function
		if production == True:		
			player_a_deck = obfuscate(player_a_deck)
			player_b_deck = obfuscate(player_b_deck)
		
		# Context for form
		context['player_a_deck_form'] = player_a_deck
		context['player_b_deck_form'] = player_b_deck
		context['index'] = index
		
		# If game is over, create a new deck to add to form for new game
		if game_status == "Over":
			new_deck(context)
	return render(request, 'krig/index.html', context)

Og her er skabelonen index.html:

{% load static %}
{% spaceless %}
<!doctype html>
<html lang="da">
	<head>
		<title>Krig!</title>
		<meta name="description" content="Spil det populære, vanedannende kortspil krig mod computeren - online!">
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="{% static "krig/style.css" %}">
		<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
		<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
		<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
		<link rel="manifest" href="/site.webmanifest">
		<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
		<meta name="msapplication-TileColor" content="#ffc40d">
		<meta name="theme-color" content="#ffffff">
		{% comment %}Most of stylesheet is loaded externally, but logic to size images in case of war is kept in template{% endcomment %}
		{% if current_index > 0 %}
		<style>
			img {
				width: 22%;
				display: inline;
			}
		</style>
		{% endif %}
	</head>
	<body>
		<h1>Krig</h1>
		
		{% comment %}Status message of current round or game is displayed{% endcomment %}
		<p class="status">
			{{ message }}
		</p>
		
		{% comment %}Page is divided in two-column grid. Each column is aligned towards vertical center of page{% endcomment %}
		<div class="grid">
			{% comment %}Player a ("You") column{% endcomment %}
			<div class="item text-right">
				<p>Dig</p>

				{% comment %}If any cards are left to turn, show number, if no cards are left, write no cards left{% endcomment %}
				<p class="cardsleft">
					{% if a_remaining_in_deck > 0 %}
						{{ a_remaining_in_deck }} kort tilbage i bunken
					{% elif a_remaining_in_deck == 0 %}
						Ingen kort tilbage!
					{% endif %}
				</p>

				{% comment %}Back of card (deck) is shown if cards are left in deck or game has not begun{% endcomment %}
				{% if a_remaining_in_deck > 0 or not game_status %}
					<img src="{% static 'krig/back_r.svg' %}">
				{% endif %}

				{% comment %}Loop to show player's turned cards.{% endcomment %}
				{% for card in a_cards_on_table %}
					{% if card.1 == True %}
						<img src="{% static 'krig/'|add:card.0|add:'.svg' %}"><br>
					{% else %}
						<img src="{% static 'krig/back_r.svg' %}">
					{% endif %}
				{% endfor %}
			</div>

			{% comment %}Player b ("Computer") column{% endcomment %}
			<div class="item text-left">
				<p>Computeren</p>
				{% comment %}If any cards are left to turn, show number, if no cards are left, write no cards left{% endcomment %}
				<p class="cardsleft">
					{% if b_remaining_in_deck > 0 %}
						{{ b_remaining_in_deck }} kort tilbage i bunken
					{% elif b_remaining_in_deck == 0 %}
						Ingen kort tilbage!
					{% endif %}
				</p>

				{% comment %}
					The order of the deck and the first turned card is different for player b who plays on the right side.
					Therefore if there is a first card in player b's cards on table that card is shown.
				{% endcomment %}
				{% if b_cards_on_table.0 %}
					<img src="{% static 'krig/'|add:b_cards_on_table.0.0|add:'.svg' %}">
				{% endif %}

				{% comment %}If b has cards left in deck or game has not started, show back of deck{% endcomment %}
				{% if b_remaining_in_deck > 0 or not game_status %}
						<img src="{% static 'krig/back_r.svg' %}">
				{% endif %}
				<br>
				
				{% comment %}
					Due to the order of player b's shown cards being different than for player a, this loop to show cards
					in case of war is a little different from player a's.
					The slices variable contains pairs of values saved as strings that the Django template filter |slice can
					understand, e.g. "1:5". These are looped through so that only parts of b_cards_on_table corresponding to
					the slice is looped through for each single, double, etc. war. The loop through b_cards_on_table is reversed
					because the card being turned is shown left of the hidden cards in the war.
				{% endcomment %}
				{% for slice_cut in slices %}
					{% for card in b_cards_on_table|slice:slice_cut reversed %}
						{% if card.1 == True %}
							<img src="{% static 'krig/'|add:card.0|add:'.svg' %}">
						{% else %}
							<img src="{% static 'krig/back_r.svg' %}">
						{% endif %}
					{% endfor %}<br>
				{% endfor %}
			</div>
		</div>

		{% comment %}
			This form is used for user input with the text in the button depending on whether user is on:
			1) Starting page: User can start a game
			2) In an ongoing game: User can turn next card
			3) In a game that has ended: User can start a new game
		{% endcomment %}
		<form class="next" action="{% url 'krig_index' %}" method="post">
			{% csrf_token %}
			<input name="player_a_deck" type="hidden" value="{{ player_a_deck_form }}">
			<input name="player_b_deck" type="hidden" value="{{ player_b_deck_form }}">
			<input name="index" type="hidden" value="{{ index }}">
			<button type="submit">{% if not game_status %}Start spillet{% elif game_status == "Going on" %}Vend næste kort{% elif game_status == "Over" %}Start nyt spil{% endif %}</button>
		</form>
	</body>
</html>
{% endspaceless %}

God fornøjelse!

Et nyt bud på en simulation af krig

Min Python-simulation af kortspillet Krig var ikke særlig elegant. Ved krig og dobbelt-krig osv. var en masse “if”-sætninger inde i hinanden med samme logik. (Jeg fandt også nogle dumme fejl, så jeg har opdateret det oprindelige indlæg.)

Derfor har jeg prøvet at skrive en ny version.

Den fungerer fint og giver følgende output ved 1.000.000 spil:

Der blev spillet 1000000 spil
Det gennemsnitlige antal dueller var 177.217668
Det højeste antal dueller var 2238
Det laveste antal dueller var 3
Den spiller med højest sum af kort vandt 573276 gange (57%)
Den spiller med højest sum af kort tabte 397771 gange (40%)
Uafgjorte spil: 1
Antal enkeltkrig, dobbeltkrig, osv.: 12348559, 886651, 60655, 3722, 218, 11, 2
Vendte kort uden krig og med krig: 176766958, 13299818
Spillene tog 225.4 sekunder

Det nye program:

# KRIG #
import time
start_time = time.time()
import random

number_of_games_to_play = 1000000
number_of_games_counter = 0
number_of_plays_list = []
highest_deck_won = 0
highest_deck_lost = 0
equal_games = 0
war_types = [0,0,0,0,0,0,0]
war_or_not_war = [0,0]

# Loop to play games
percentage_copy = 0
i = 0
while i < number_of_games_to_play:
	# One is added to i so loop finishes once number of games have been played
	i += 1
	
	# Prints percentage done with 1 decimal every time it changes
	percentage_completed = round((i/number_of_games_to_play*100), 1)
	if percentage_copy != percentage_completed:
		print("{}% done".format(percentage_completed))
	percentage_copy = percentage_completed

	# Create a deck, shuffle it and divide between players
	deck = [2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,14]
	random.shuffle(deck)
	player_a_deck = deck[0:26]
	player_b_deck = deck[26:52]

	# Which player has the highest sum of cards
	card_sum_a = sum(player_a_deck)
	card_sum_b = sum(player_b_deck)
	if card_sum_a > card_sum_b:
		highest_deck = "a"
	elif card_sum_a < card_sum_b:
		highest_deck = "b"
	else:
		highest_deck = "equal"
	
	# Loop to turn cards within games
	number_of_plays = 0
	index = 1
	while True:
		try:
			if index == 1:
				number_of_plays += 1	# Add 1 to number of plays counter
				war_count = 0			# Reset war counter	
			# Player a has the largest card
			if player_a_deck[index-1] > player_b_deck[index-1]:
				war_or_not_war[0] += 1
				player_a_deck.extend(player_a_deck[:index])
				player_a_deck.extend(player_b_deck[:index])	
				del player_a_deck[:index]
				del player_b_deck[:index]
				index = 1			# If a play is decided, index is reset
			# Player b has the largest card
			elif player_a_deck[index-1] < player_b_deck[index-1]:
				war_or_not_war[0] += 1
				# Cards are added in different order to deck in order to avoid (game) risk of going on forever (infinite loop)!
				player_b_deck.extend(player_b_deck[:index])	
				player_b_deck.extend(player_a_deck[:index])
				del player_a_deck[:index]
				del player_b_deck[:index]
				index = 1			# If a play is decided, index is reset
			# War is on!
			else:
				war_or_not_war[1] += 1
				index += 4			# In case of war the index is upped by four cards
				war_types[war_count] += 1
				war_count += 1
		# If a player has too few cards left to participate, game is over
		except IndexError:
			# If a player had no cards left and index is 1, the game was already over, so number of plays is corrected
			if index == 1:
				number_of_plays -= 1
			break
	
	# Single game is over #
	# Compare deck sizes to decide winner and add values to counters and lists
	deck_a = len(player_a_deck)
	deck_b = len(player_b_deck)
	if deck_a > deck_b:
		if highest_deck == "a":
			highest_deck_won += 1
		elif highest_deck == "b":
			highest_deck_lost += 1
	elif deck_a < deck_b:
		if highest_deck == "a":
			highest_deck_lost += 1
		elif highest_deck == "b"    :
			highest_deck_won += 1
	else:
		equal_games += 1
	
	number_of_plays_list.append(number_of_plays)
	number_of_games_counter += 1
	
# All games are over #
print("Der blev spillet {} spil".format(number_of_games_counter))
print("Det gennemsnitlige antal dueller var {}".format(sum(number_of_plays_list)/len(number_of_plays_list)))
print("Det højeste antal dueller var {}".format(max(number_of_plays_list)))
print("Det laveste antal dueller var {}".format(min(number_of_plays_list)))
print("Den spiller med højest sum af kort vandt {} gange ({}%)".format(highest_deck_won, round(highest_deck_won/number_of_games_counter*100)))
print("Den spiller med højest sum af kort tabte {} gange ({}%)".format(highest_deck_lost, round(highest_deck_lost/number_of_games_counter*100)))
print("Uafgjorte spil: {}".format(equal_games))
print("Antal enkeltkrig, dobbeltkrig, osv.: {}".format(", ".join(str(x) for x in war_types)))
print("Vendte kort uden krig og med krig: {}".format(", ".join(str(x) for x in war_or_not_war)))
print("Spillene tog {} sekunder".format(round(time.time() - start_time, 1)))

Ting du ikke vil vide om kortspillet Krig

Hvis man tilfældigvis har et barn i 5-årsalderen, kan man spille kortspillet Krig. Kortene blandes og deles ligeligt mellem 2 spillere, hver spiller vender et kort fra sin bunke samtidig, højeste kort vender, hvis kortene er lige høje, er der krig. Det er så enkelt, at man lige så godt kunne få en computer til at spille det.

Derfor skrev jeg et lille program i Python, der kan simulere kortspillet.

Jeg opdagede et hul i reglerne: Der er ingen steder, der beskriver, hvad der sker, når en spiller ikke har kort nok til at deltage i en krig (eller en dobbelt-krig, tredobbelt-krig, osv.) Jeg besluttede, at hvis en spiller på et tidspunkt mangler kort til at kunne deltage, taber den spiller, der ikke har kort nok til at deltage. I den meget sjældne situation, at begge spillere ikke har nok kort til at deltage (en mange-mange-dobbelt-krig i starten af spillet), vinder den spiller, der har flest kort. Har begge spillere lige mange kort, bliver det uafgjort.

Jeg fik computeren til at spille 1 million spil Krig, og her er hvad jeg kan fortælle dig om Krig, som du ikke vil vide:

  • Det gennemsnitlige antal dueller i et spil krig er 177
  • Spillet med flest dueller havde 1.825 dueller
  • Spillet med færrest havde 4 dueller
  • Spilleren med den højeste sum af kort efter kortene blev blandet vandt 573.405 gange
  • Spilleren med den laveste sum af kort vandt 397.602 gange
  • I løbet af spillene blev der spillet:
    • Enkeltkrig: 12.366.762 gange
    • Dobbeltkrig: 888.024 gange
    • Trippelkrig: 60.727 gange
    • Firdobbeltkrig: 3.852 gange
    • Femdobbeltkrig: 206 gange
    • Seksdobbeltkrig: 10 gange

Her er programmet:

import random

krig1 = 0
krig2 = 0
krig3 = 0
krig4 = 0
krig5 = 0
krig6 = 0
krig7 = 0

number_of_plays_list = []
not_war = 0
war = 0

highest_deck_won = 0
highest_deck_lost = 0
equal_games = 0

i = 0
number_of_games = 1000000

while i <= number_of_games:
	number_of_plays_counter = 0
	deck = [2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,14]
	random.shuffle(deck)

	player_a_deck = deck[0:26]
	player_b_deck = deck[26:52]

	if sum(player_a_deck) > sum(player_b_deck):
		highest_deck = "a"
	elif sum(player_a_deck) < sum(player_b_deck):
		highest_deck = "b"
	else:
		highest_deck = "equal"

	while len(player_a_deck) > 0 and len(player_b_deck) > 0:
		number_of_plays_counter += 1
		if player_a_deck[0] > player_b_deck[0]:
			not_war += 1
			player_a_deck.append(player_a_deck[0])
			player_a_deck.append(player_b_deck[0])
			del player_a_deck[0]
			del player_b_deck[0]
		elif player_a_deck[0] < player_b_deck[0]:
			not_war += 1
			player_b_deck.append(player_b_deck[0])
			player_b_deck.append(player_a_deck[0])
			del player_a_deck[0]
			del player_b_deck[0]
		elif player_a_deck[0] == player_b_deck[0]:
			war += 1
			krig1 += 1
			if len(player_a_deck) >= 5 and len(player_b_deck) >= 5:
				if player_a_deck[4] > player_b_deck[4]:
					player_a_deck.extend(player_a_deck[0:5])
					player_a_deck.extend(player_b_deck[0:5])
					del player_a_deck[0:5]
					del player_b_deck[0:5]
				elif player_a_deck[4] < player_b_deck[4]:
					player_b_deck.extend(player_b_deck[0:5])
					player_b_deck.extend(player_a_deck[0:5])
					del player_a_deck[0:5]
					del player_b_deck[0:5]
				elif player_a_deck[4] == player_b_deck[4]:
					krig2 += 1
					if len(player_a_deck) >= 9 and len(player_b_deck) >= 9:			
						if player_a_deck[8] > player_b_deck[8]:
							player_a_deck.extend(player_a_deck[0:9])
							player_a_deck.extend(player_b_deck[0:9])
							del player_a_deck[0:9]
							del player_b_deck[0:9]
						elif player_a_deck[8] < player_b_deck[8]:
							player_b_deck.extend(player_b_deck[0:9])
							player_b_deck.extend(player_a_deck[0:9])
							del player_a_deck[0:9]
							del player_b_deck[0:9]	
						elif player_a_deck[8] == player_b_deck[8]:
							krig3 += 1
							if len(player_a_deck) >= 13 and len(player_b_deck) >= 13:
								if player_a_deck[12] > player_b_deck[12]:
									player_a_deck.extend(player_a_deck[0:13])
									player_a_deck.extend(player_b_deck[0:13])
									del player_a_deck[0:13]
									del player_b_deck[0:13]
								elif player_a_deck[12] < player_b_deck[12]:
									player_b_deck.extend(player_b_deck[0:13])
									player_b_deck.extend(player_a_deck[0:13])
									del player_a_deck[0:13]
									del player_b_deck[0:13]	
								elif player_a_deck[12] == player_b_deck[12]:
									krig4 += 1
									if len(player_a_deck) >= 17 and len(player_b_deck) >= 17:
										if player_a_deck[16] > player_b_deck[16]:
											player_a_deck.extend(player_a_deck[0:17])
											player_a_deck.extend(player_b_deck[0:17])
											del player_a_deck[0:17]
											del player_b_deck[0:17]
										elif player_a_deck[16] < player_b_deck[16]:
											player_b_deck.extend(player_b_deck[0:17])
											player_b_deck.extend(player_a_deck[0:17])
											del player_a_deck[0:17]
											del player_b_deck[0:17]
										elif player_a_deck[16] == player_b_deck[16]:
											krig5 += 1
											if len(player_a_deck) >= 21 and len(player_b_deck) >= 21:
												if player_a_deck[20] > player_b_deck[20]:
													player_a_deck.extend(player_a_deck[0:21])
													player_a_deck.extend(player_b_deck[0:21])
													del player_a_deck[0:21]
													del player_b_deck[0:21]
												elif player_a_deck[20] < player_b_deck[20]:
													player_b_deck.extend(player_b_deck[0:21])
													player_b_deck.extend(player_a_deck[0:21])
													del player_a_deck[0:21]
													del player_b_deck[0:21]										
												elif player_a_deck[20] == player_b_deck[20]:
													krig6 += 1
													if len(player_a_deck) >= 25 and len(player_b_deck) >= 25:
														if player_a_deck[24] > player_b_deck[24]:
															player_a_deck.extend(player_a_deck[0:25])
															player_a_deck.extend(player_b_deck[0:25])
															del player_a_deck[0:25]
															del player_b_deck[0:25]
														elif player_a_deck[24] < player_b_deck[24]:
															player_b_deck.extend(player_b_deck[0:25])
															player_b_deck.extend(player_a_deck[0:25])
															del player_a_deck[0:25]
															del player_b_deck[0:25]
														elif player_a_deck[24] == player_b_deck[24]:
															krig7 += 1
															break
													else:
														break
											else:
												break
									else:
										break
							else:
								break
					else:
						break
			else:
				break
	if len(player_a_deck) > len(player_b_deck):
		if highest_deck == "a":
			highest_deck_won += 1
		elif highest_deck == "b"	:
			highest_deck_lost += 1
	elif len(player_a_deck) < len(player_b_deck):
		if highest_deck == "a":
			highest_deck_lost += 1
		elif highest_deck == "b"	:
			highest_deck_won += 1
	else:
		equal_games += 1
	number_of_plays_list.append(number_of_plays_counter)
	i += 1
	print(i/number_of_games)

print("Der blev spillet {} spil".format(number_of_games))
print("Det gennemsnitlige antal dueller var {}".format(sum(number_of_plays_list)/len(number_of_plays_list)))
print("Det højeste antal dueller var {}".format(max(number_of_plays_list)))
print("Det laveste antal dueller var {}".format(min(number_of_plays_list)))
print("Den spiller med højest sum af kort vandt {} gange".format(highest_deck_won))
print("Den spiller med højest sum af kort tabte {} gange".format(highest_deck_lost))
print(krig1, krig2, krig3, krig4, krig5, krig6, krig7)
print(not_war, war)
print("Uafgjorte spil: {}".format(equal_games))