Last active
August 29, 2015 14:20
-
-
Save molcay/e59d1d27d1f92b31e17e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random # başlangıç noktası her seferinde rasgele olarak seçilecek. | |
N = 8 # satranc tahtasının büyüklüğü. 5 den büyük olmalı | |
move_list = [] # satranç tahtası üzerinde hangi noktalara basıldığını tutacak | |
def gen_pos_moves(x,y): # bu fonksiyon olası hareket listesini döndürecek | |
offset = [-1, -2, 1, 2] | |
# possible = [ (x+a, y+b) for (a,b) in [ (-2,1), (-1,2), (1,2), (2,1), (2,-1), (1,-2), (-1, -2), (-2, -1)] ] | |
possible = [ (x+a, y+b) for a in offset for b in offset if abs(a) != abs(b)] | |
return [ (a,b) for (a,b) in possible if 0<=a<N and 0<=b<N and (a,b) not in move_list] | |
def move(start_x, start_y): | |
move_list.append((start_x, start_y)) | |
#print("Hareket Listesi:", move_list) | |
while (len(move_list) < 64): | |
pos_move_list = gen_pos_moves(move_list[-1][0], move_list[-1][1]) | |
#print("Olası Hareket Listesi:",pos_move_list) | |
pos_move_numbers = [] | |
for (x,y) in pos_move_list: | |
pos_move_numbers.append(len(gen_pos_moves(x, y))) | |
#print("Bir Sonraki Adımda Olası Hareket Sayısı Listesi: ", pos_move_numbers) | |
next_move = pos_move_list[pos_move_numbers.index(min(pos_move_numbers))] | |
#print("Yapılacak Hareket:", next_move) | |
move_list.append(next_move) | |
return move_list | |
(x, y) = (random.randint(0, N - 1), random.randint(0, N - 1)) # başlangıç noktası rasgele seçiliyor. Başlangıç noktası 0 ile gösterilir. | |
move(x,y) # hareket burada yapılıyor | |
#print(move(x, y)) | |
board = a=[[0 for i in range(N)] for j in range(N)] # son çıktı için yeni N x N lik tahta yapılıyor | |
for cell in (move_list): # move_list i board un içine aktarıyoruz | |
board[cell[0]][cell[1]] = move_list.index(cell) | |
for i in board: # board u ekrana yazdırıyoruz | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment