Commit aa20d554 authored by lengfeld8's avatar lengfeld8
Browse files

Upload New File

parent a55f0116
import main
from alphaBeta import AlphaBeta
import numpy as np
import time
import timeit
board_full7 = "bwwbbww/wbbwwbb/bwbwbbw/-bwwbbw/bwbbbw-/w-wwwbb/-wb---w"
board_full9 = "bw-wbwbw-/-bbb-bwbb/wwwbwwwww/bbwwbbbbw/bb-wbbwbw/wwbwwbbbw/bb-bwbww-/wwwwbw-bw/--bbwbw-b"
board_full11 = "bwb-bw-bwb-/wbwbwwbwwbw/bw-wb-wbbwb/wbwbwbwwbbw/bbwbw-bwbww/-wbbwbwwbbb/wb-wbwb-wbw/bbwbb-wbw-b/wwb-wbbwb-w/wbwbwwwbw-b/bw-wb-bwbw-"
board_halffull7 = "bww--ww/wbb--bb/bw--bbw/----wbw/b-bbb--/w-www--/-wb----"
board_halffull9 = "bw-wbwbw-/-b-b-bwbb/-w---w-ww/-bwwbb-bw/bb---bw--/wwbw--bbw/bb-b--ww-/wwwwbw-b-/--b--bw--"
board_halffull11 = "bw--bw-bwb-/-b-bw--wwbw/-w-w------b/wbwb-bw--bw/b--bw-b--w-/----w-w--b-/wb--b-b-wbw/b-wb--wbw-b/w-b-----b-w/-bwbw-wbw-b/-w-wb-bwbw-"
board_empty7 = "-------/-------/-------/-------/-------/-------/-------"
board_empty9 = "---------/---------/---------/---------/---------/---------/---------/---------/---------"
board_empty11 = "-----------/-----------/-----------/-----------/-----------/-----------/-----------/-----------/-----------/-----------/-----------"
board_7e = np.zeros(7 * 7)
board_7hf = np.zeros(7 * 7)
board_7f = np.zeros(7 * 7)
board_9e = np.zeros(9 * 9)
board_9hf = np.zeros(9 * 9)
board_9f = np.zeros(9 * 9)
board_11e = np.zeros(11 * 11)
board_11hf = np.zeros(11 * 11)
board_11f = np.zeros(11 * 11)
main_7f = main.Board(7, board_7f)
main_7hf = main.Board(7, board_7hf)
main_7e = main.Board(7, board_7e)
main_9f = main.Board(9, board_9f)
main_9hf = main.Board(9, board_9hf)
main_9e = main.Board(9, board_9e)
main_11f = main.Board(11, board_11f)
main_11hf = main.Board(11, board_11hf)
main_11e = main.Board(11, board_11e)
main_7hf.string_parse(board_halffull7)
main_7f.string_parse(board_full7)
main_7e.string_parse(board_empty7)
main_9hf.string_parse(board_halffull9)
main_9f.string_parse(board_full9)
main_9e.string_parse(board_empty9)
main_11hf.string_parse(board_halffull11)
main_11f.string_parse(board_full11)
main_11e.string_parse(board_empty11)
def benchmark_generate_moves():
total = 0
for i in range(10000):
start = time.time_ns()
main_7e.generate_moves()
end = time.time_ns()
total += end - start
print("Benchmark Calculate Possible Moves 7x7 (Board empty):", total / 10000, "per Loop")
total = 0
for i in range(10000):
start = time.time_ns()
main_7hf.generate_moves()
end = time.time_ns()
total += end - start
print("Benchmark Calculate Possible Moves 7x7 (Board halffull):", total / 10000, "per Loop")
total = 0
for i in range(10000):
start = time.time_ns()
main_7f.generate_moves()
end = time.time_ns()
total += end - start
print("Benchmark Calculate Possible Moves 7x7 (Board full):", total / 10000, "per Loop")
total = 0
for i in range(10000):
start = time.time_ns()
main_9e.generate_moves()
end = time.time_ns()
total += end - start
print("Benchmark Calculate Possible Moves 9x9 (Board empty):", total / 10000, "per Loop")
total = 0
for i in range(10000):
start = time.time_ns()
main_9hf.generate_moves()
end = time.time_ns()
total += end - start
print("Benchmark Calculate Possible Moves 9x9 (Board halffull):", total / 10000, "per Loop")
total = 0
for i in range(10000):
start = time.time_ns()
main_9f.generate_moves()
end = time.time_ns()
total += end - start
print("Benchmark Calculate Possible Moves 9x9 (Board full):", total / 10000, "per Loop")
total = 0
for i in range(10000):
start = time.time_ns()
main_11e.generate_moves()
end = time.time_ns()
total += end - start
print("Benchmark Calculate Possible Moves 11x11 (Board empty):", total / 10000, "per Loop")
total = 0
for i in range(10000):
start = time.time_ns()
main_11hf.generate_moves()
end = time.time_ns()
total += end - start
print("Benchmark Calculate Possible Moves 11x11 (Board halffull):", total / 10000, "per Loop")
total = 0
for i in range(10000):
start = time.time_ns()
main_11f.generate_moves()
end = time.time_ns()
total += end - start
print("Benchmark Calculate Possible Moves 11x11 (Board full):", total / 10000, "per Loop")
def benchmark_evaluate_board():
total = 0
for i in range(10000):
start = time.time_ns()
main_7e.eval_func(main_7e.board)
end = time.time_ns()
total += end - start
print("Benchmark Evaluation Board 7x7 (Board empty):", total / 10000, "per Loop")
total = 0
for i in range(10000):
start = time.time_ns()
main_7hf.eval_func(main_7hf.board)
end = time.time_ns()
total += end - start
print("Benchmark Evaluation Board 7x7 (Board halffull):", total / 10000, "per Loop")
total = 0
for i in range(10000):
start = time.time_ns()
main_7f.eval_func(main_7f.board)
end = time.time_ns()
total += end - start
print("Benchmark Evaluation Board 7x7 (Board full):", total / 10000, "per Loop")
def benchmark_alpha_beta():
horizon = 1
time_alpha_beta_empty = AlphaBeta(7, horizon)
time_alpha_beta_empty.boardObject.string_parse(board_empty7)
possible_moves_empty = time_alpha_beta_empty.boardObject.generate_moves()
time_alpha_beta_half_full = AlphaBeta(7, horizon)
time_alpha_beta_half_full.boardObject.string_parse(board_halffull7)
possible_moves_half_full = time_alpha_beta_half_full.boardObject.generate_moves()
time_alpha_beta_full = AlphaBeta(7, horizon)
time_alpha_beta_full.boardObject.string_parse(board_full7)
possible_moves_full = time_alpha_beta_full.boardObject.generate_moves()
#total = 0
#for i in range(10000):
# start = time.time_ns()
# time_alpha_beta_empty.start_pruning(1, possible_moves_empty)
# end = time.time_ns()
# total += end - start
# print("Benchmark Alpha-Beta 7x7 (Board empty):", total / 10000, "per Loop with a horizon of ", horizon)
total = 0
for i in range(1000):
start = time.time_ns()
time_alpha_beta_half_full.start_pruning(1, possible_moves_half_full)
end = time.time_ns()
total += end - start
print("Benchmark Alpha-Beta 7x7 (Board halffull):", total / 1000, "per Loop with a horizon of ", horizon)
total = 0
for i in range(1000):
start = time.time_ns()
time_alpha_beta_full.start_pruning(1, possible_moves_full)
end = time.time_ns()
total += end - start
print("Benchmark Alpha-Beta 7x7 (Board full):", total / 1000, "per Loop with a horizon of ", horizon)
if __name__ == '__main__':
# benchmark_generate_moves()
# benchmark_evaluate_board()
benchmark_alpha_beta()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment