Created
November 25, 2018 22:04
-
-
Save doraneko94/8d73e171fa3fcf3322175c789ada8a39 to your computer and use it in GitHub Desktop.
"Hey, that's my fish!"-ish CUI game. Because this game is my study and not user-friendly, please buy this board game or official App if you want to really enjoy "Hey, that's my fish!"
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 | |
alpha = ["A", "B", "C", "D"] | |
fishes = [1,1,1,1,1,1,1,1,1,1, | |
1,1,1,1,1,1,1,1,1,1, | |
1,1,1,1,1,1,1,1,1,1, | |
2,2,2,2,2,2,2,2,2,2, | |
2,2,2,2,2,2,2,2,2,2, | |
3,3,3,3,3,3,3,3,3,3] | |
f = random.sample(fishes, len(fishes)) | |
ice = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], | |
[0,f[0], f[1], f[2], f[3], f[4], f[5], f[6], 0, 0, 0, 0, 0], | |
[0,f[7], f[8], f[9], f[10], f[11], f[12], f[13], f[14], 0, 0, 0, 0], | |
[0, 0, f[15], f[16], f[17], f[18], f[19], f[20], f[21], 0, 0, 0, 0], | |
[0, 0, f[22], f[23], f[24], f[25], f[26], f[27], f[28], f[29], 0, 0, 0], | |
[0, 0, 0, f[30], f[31], f[32], f[33], f[34], f[35], f[36], 0, 0, 0], | |
[0, 0, 0, f[37], f[38], f[39], f[40], f[41], f[42], f[43], f[44], 0, 0], | |
[0, 0, 0, 0, f[45], f[46], f[47], f[48], f[49], f[50], f[51], 0, 0], | |
[0, 0, 0, 0, f[52], f[53], f[54], f[55], f[56], f[57], f[58], f[59], 0], | |
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] | |
def print_ice(ice): | |
alpha = ["A", "B", "C", "D"] | |
rows = [[" " + str(j) if j >= 0 else " " + alpha[int(j * (-1) / 10) - 1] for j in ice[i+1][1+int(i/2):8+int(i/2)]] if i%2==0 else [str(j) + " " if j >= 0 else alpha[int(j * (-1) / 10) - 1] + " " for j in ice[i+1][1+int(i/2):9+int(i/2)]] for i in range(8)] | |
for i in range(8): | |
print("".join(rows[i])) | |
return | |
print_ice(ice) | |
print("") | |
def How_many_players(): | |
player_num = input("How many players? ... ") | |
try: | |
player_num = int(player_num) | |
except: | |
print("Please enter 2, 3 or 4.") | |
return How_many_players() | |
if player_num < 2 or player_num > 4: | |
print("This game is for 2 ~ 4 people.") | |
return How_many_players() | |
else: | |
return player_num | |
player_num = How_many_players() | |
penguins = [[0, 0, 0, 0], | |
[0, 0, 0, 0], | |
[0, 0, 0, 0], | |
[0, 0, 0, 0]] | |
def Where_is_penguin(i, j, ice, penguins): | |
alpha = ["A", "B", "C", "D"] | |
print("Player {},".format(alpha[j])) | |
if i == 0: | |
penguin_pos = input("Put your 1st pengiun. ... ") | |
if i == 1: | |
penguin_pos = input("Put your 2nd pengiun. ... ") | |
if i == 2: | |
penguin_pos = input("Put your 3rd pengiun. ... ") | |
if i == 3: | |
penguin_pos = input("Put your 4th pengiun. ... ") | |
try: | |
row = int(penguin_pos[0]) | |
column = int(penguin_pos[1]) | |
except: | |
print("Please enter 2 numbers.") | |
print("For example, if you enter \"34\" then your penguin is on row=3 and column=4.") | |
return Where_is_penguin(i, j, ice, penguins) | |
if column < 0 or column > 7 or row < 0 or row > 7: | |
print("Please enter 2 numbers that are 0 ~ 7.") | |
return Where_is_penguin(i, j, ice, penguins) | |
elif row in [0,2,4,6] and column > 6: | |
print("Row 0, 2, 4 and 6 has only 7 (0 ~ 6) columns.") | |
return Where_is_penguin(i, j, ice, penguins) | |
elif ice[row+1][column+int(row/2)+1] != 1: | |
print("You can put penguins on unoccupied ice with 1 fish.") | |
return Where_is_penguin(i, j, ice, penguins) | |
else: | |
ice[row+1][column+int(row/2)+1] = ((j+1)*10 + i) * -1 | |
penguins[j][i] = row * 10 + column | |
return ice, penguins | |
for i in range(6-player_num): | |
for j in range(player_num): | |
ice, penguins = Where_is_penguin(i, j, ice, penguins) | |
print_ice(ice) | |
reserve = [[1, 1, 1, 1], | |
[1, 1, 1, 1], | |
[1, 1, 1, 1], | |
[1, 1, 1, 1]] | |
def Which_penguin(turn, ice, penguins, can_move): | |
alpha = ["A", "B", "C", "D"] | |
print("Player {},".format(alpha[turn])) | |
penguin_pos = input("Which penguin do you move? ... ") | |
try: | |
row = int(penguin_pos[0]) | |
column = int(penguin_pos[1]) | |
except: | |
print("Please enter 2 numbers.") | |
print("For example, if you enter \"34\" then the penguin on row=3 and column=4 is selected.") | |
return Which_penguin(turn, ice, penguins, can_move) | |
if row*10+column not in penguins[turn]: | |
print("Your penguin is not on \"{}\".".format(str(row)+str(column))) | |
return Which_penguin(turn, ice, penguins, can_move) | |
else: | |
row_ice = row + 1 | |
column_ice = column + int((row_ice+1)/2) | |
penguin_num = int(str(ice[row_ice][column_ice] * (-1))[1]) | |
if len(can_move[penguin_num]) == 0: | |
print("This penguin can't move.") | |
return Which_penguin(turn, ice, penguins, can_move) | |
else: | |
return row, column, penguin_num | |
def Move_where(penguin_num, ice, penguins, can_move): | |
penguin_pos = input("Where do you move this penguin to? ... ") | |
try: | |
row = int(penguin_pos[0]) | |
column = int(penguin_pos[1]) | |
except: | |
print("Please enter 2 numbers.") | |
print("For example, if you enter \"34\" then the selected penguin is moved to row=3 and column=4.") | |
return Move_where(penguin_num, ice, penguins, can_move) | |
if row*10+column not in can_move[penguin_num]: | |
print("The selected penguin can't move to \"{}\".".format(str(row)+str(column))) | |
return Move_where(penguin_num, ice, penguins, can_move) | |
else: | |
return row, column | |
print("") | |
print("Game start.") | |
print("") | |
fish_list = [0, 0, 0, 0] | |
game_key = 0 | |
for i in range(player_num*60): | |
print_ice(ice) | |
turn = i%player_num | |
can_move = [] | |
move_key = 0 | |
for j in range(6-player_num): | |
row = int(str(penguins[turn][j]).zfill(2)[0]) + 1 | |
column = int(str(penguins[turn][j]).zfill(2)[1]) + int((row+1)/2) | |
ice_x = ice[row] | |
x_p = [k if k >= 0 else 0 for k in ice_x[column+1:]] | |
x_n = [k if k >= 0 else 0 for k in ice_x[:column]][::-1] | |
ice_y = [k[column] for k in ice] | |
y_p = [k if k >= 0 else 0 for k in ice_y[row+1:]] | |
y_n = [k if k >= 0 else 0 for k in ice_y[:row]][::-1] | |
ice_z = [ice[k][l] if l >= 0 and l <= 12 else 0 for k, l in enumerate(range(column-row, column-row+10))] | |
z_p = [k if k >= 0 else 0 for k in ice_z[row+1:]] | |
z_n = [k if k >= 0 else 0 for k in ice_z[:row]][::-1] | |
x_can = [(row - 1)*10 + (column - int((row + 1)/2) + k + 1) for k in range(len(x_p[:x_p.index(0)]))] + [(row - 1)*10 + (column - int((row + 1)/2) - k - 1) for k in range(len(x_n[:x_n.index(0)]))] | |
y_can = [(row + k)*10 + (column - int((row + k + 2)/2)) for k in range(len(y_p[:y_p.index(0)]))] + [(row - k - 2)*10 + (column - int((row - k)/2)) for k in range(len(y_n[:y_n.index(0)]))] | |
z_can = [(row + k)*10 + (column - int((row + k + 2)/2) + k + 1) for k in range(len(z_p[:z_p.index(0)]))] + [(row - k - 2)*10 + (column - int((row - k)/2) - k - 1) for k in range(len(z_n[:z_n.index(0)]))] | |
can_move.append(x_can + y_can + z_can) | |
if len(can_move[j]) != 0: | |
move_key = 1 | |
if move_key == 0: | |
print("Player {},".format(alpha[turn])) | |
print("All of your penguins can't move!") | |
for j in range(player_num): | |
print("Player {} : {} fishes.".format(alpha[j], fish_list[j])) | |
game_key += 1 | |
if game_key == player_num: | |
break | |
else: | |
continue | |
else: | |
game_key = 0 | |
row_0, column_0, penguin_num = Which_penguin(turn, ice, penguins, can_move) | |
row_1, column_1 = Move_where(penguin_num, ice, penguins, can_move) | |
penguins[turn][penguin_num] = row_1*10 + column_1 | |
fish_list[turn] += reserve[turn][penguin_num] | |
row_0_ice = row_0 + 1 | |
column_0_ice = column_0 + int((row_0_ice+1)/2) | |
row_1_ice = row_1 + 1 | |
column_1_ice = column_1 + int((row_1_ice+1)/2) | |
ice[row_0_ice][column_0_ice] = 0 | |
reserve[turn][penguin_num] = ice[row_1_ice][column_1_ice] | |
ice[row_1_ice][column_1_ice] = (-1) * ((turn + 1)*10 + penguin_num) | |
for j in range(player_num): | |
print("Player {} : {} fishes.".format(alpha[j], fish_list[j])) | |
print("") | |
print("Game set!") | |
print("") | |
for j in range(player_num): | |
print("Player {} : {} fishes.".format(alpha[j], fish_list[j])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment