Best Python code snippet using ATX
Game.py
Source:Game.py
1 # Ludo game with Aditya#2from tkinter import *3from tkinter import messagebox4from PIL import Image,ImageTk5import time6from random import randint7class Ludo:8 def __init__(self, root,six_side_block,five_side_block,four_side_block,three_side_block,two_side_block,one_side_block):9 self.window = root10 # Make canvas11 self.make_canvas = Canvas(self.window, bg="#4d4dff", width=800, height=630)12 self.make_canvas.pack(fill=BOTH,expand=1)13 # Make some containers to store data14 self.made_red_coin = []15 self.made_green_coin = []16 self.made_yellow_coin = []17 self.made_sky_blue_coin = []18 self.red_number_label = []19 self.green_number_label = []20 self.yellow_number_label = []21 self.sky_blue_number_label = []22 self.block_value_predict = []23 self.total_people_play = []24 # Ludo block all side image store25 self.block_number_side = [one_side_block, two_side_block, three_side_block, four_side_block, five_side_block, six_side_block]26 # Use for store specific position of all coins27 self.red_coord_store = [-1, -1, -1, -1]28 self.green_coord_store = [-1, -1, -1, -1]29 self.yellow_coord_store = [-1, -1, -1, -1]30 self.sky_blue_coord_store = [-1, -1, -1, -1]31 self.red_coin_position = [0, 1, 2, 3]32 self.green_coin_position = [0, 1, 2, 3]33 self.yellow_coin_position = [0, 1, 2, 3]34 self.sky_blue_coin_position = [0, 1, 2, 3]35 for index in range(len(self.red_coin_position)):# Specific coin position set to -1 by default36 self.red_coin_position[index] = -137 self.green_coin_position[index] = -138 self.yellow_coin_position[index] = -139 self.sky_blue_coin_position[index] = -140 # Number to room to be traverse by specific color coin, store in that variable41 self.move_red_counter = 042 self.move_green_counter = 043 self.move_yellow_counter = 044 self.move_sky_blue_counter = 045 self.take_permission = 046 self.six_with_overlap = 047 self.red_store_active = 048 self.sky_blue_store_active = 049 self.yellow_store_active = 050 self.green_store_active = 051 self.six_counter = 052 self.time_for = -153 # Some variables initializes with None54 self.right_star = None55 self.down_star = None56 self.left_star = None57 self.up_star = None58 # By default some function call59 self.board_set_up()60 self.instruction_btn_red()61 self.instruction_btn_sky_blue()62 self.instruction_btn_yellow()63 self.instruction_btn_green()64 self.take_initial_control()65 def board_set_up(self):66 # Cover Box made67 self.make_canvas.create_rectangle(100, 15, 100 + (40 * 15), 15 + (40 * 15), width=6, fill="white")68 # Square box69 self.make_canvas.create_rectangle(100, 15, 100+240, 15+240, width=3, fill="red")# left up large square70 self.make_canvas.create_rectangle(100, (15+240)+(40*3), 100+240, (15+240)+(40*3)+(40*6), width=3, fill="#04d9ff")# left down large square71 self.make_canvas.create_rectangle(340+(40*3), 15, 340+(40*3)+(40*6), 15+240, width=3, fill="#00FF00")# right up large square72 self.make_canvas.create_rectangle(340+(40*3), (15+240)+(40*3), 340+(40*3)+(40*6), (15+240)+(40*3)+(40*6), width=3, fill="yellow")# right down large square73 # Left 3 box(In white region)74 self.make_canvas.create_rectangle(100, (15+240), 100+240, (15+240)+40, width=3)75 self.make_canvas.create_rectangle(100+40, (15 + 240)+40, 100 + 240, (15 + 240) + 40+40, width=3, fill="#F00000")76 self.make_canvas.create_rectangle(100, (15 + 240)+80, 100 + 240, (15 + 240) + 80+40, width=3)77 # right 3 box(In white region)78 self.make_canvas.create_rectangle(100+240, 15, 100 + 240+40, 15 + (40*6), width=3)79 self.make_canvas.create_rectangle(100+240+40, 15+40, 100+240+80, 15 + (40*6), width=3, fill="#00FF00")80 self.make_canvas.create_rectangle(100+240+80, 15, 100 + 240+80+40, 15 + (40*6), width=3)81 # up 3 box(In white region)82 self.make_canvas.create_rectangle(340+(40*3), 15+240, 340+(40*3)+(40*6), 15+240+40, width=3)83 self.make_canvas.create_rectangle(340+(40*3), 15+240+40, 340+(40*3)+(40*6)-40, 15+240+80, width=3, fill="yellow")84 self.make_canvas.create_rectangle(340+(40*3), 15+240+80, 340+(40*3)+(40*6), 15+240+120, width=3)85 # down 3 box(In white region)86 self.make_canvas.create_rectangle(100, (15 + 240)+(40*3), 100 + 240+40, (15 + 240)+(40*3)+(40*6), width=3)87 self.make_canvas.create_rectangle(100+240+40, (15 + 240)+(40*3), 100 + 240+40+40, (15 + 240)+(40*3)+(40*6)-40, width=3, fill="#04d9ff")88 self.make_canvas.create_rectangle(100 + 240+40+40, (15 + 240)+(40*3), 100 + 240+40+40+40, (15 + 240)+(40*3)+(40*6), width=3)89 # All left separation line90 start_x = 100 + 4091 start_y = 15 + 24092 end_x = 100 + 4093 end_y = 15 + 240 + (40 * 3)94 for _ in range(5):95 self.make_canvas.create_line(start_x, start_y, end_x, end_y, width=3)96 start_x+=4097 end_x+= 4098 # All right separation line99 start_x = 100+240+(40*3)+40100 start_y = 15 + 240101 end_x = 100+240+(40*3)+40102 end_y = 15 + 240 + (40 * 3)103 for _ in range(5):104 self.make_canvas.create_line(start_x, start_y, end_x, end_y, width=3)105 start_x += 40106 end_x += 40107 # All up separation done108 start_x = 100+240109 start_y = 15+40110 end_x = 100+240+(40*3)111 end_y = 15+40112 for _ in range(5):113 self.make_canvas.create_line(start_x, start_y, end_x, end_y, width=3)114 start_y += 40115 end_y += 40116 # All down separation done117 start_x = 100 + 240118 start_y = 15 + (40*6)+(40*3)+40119 end_x = 100 + 240 + (40 * 3)120 end_y = 15 + (40*6)+(40*3)+40121 for _ in range(5):122 self.make_canvas.create_line(start_x, start_y, end_x, end_y, width=3)123 start_y += 40124 end_y += 40125 # Square box(Coins containers) white region make126 self.make_canvas.create_rectangle(100+20, 15+40-20, 100 + 40 + 60 + 40 +60+20, 15+40+40+40+100-20, width=3, fill="white")127 self.make_canvas.create_rectangle(340+(40*3)+40 - 20, 15 + 40-20, 340+(40*3)+40 + 60 + 40 + 40+20+20, 15+40+40+40+100-20, width=3, fill="white")128 self.make_canvas.create_rectangle(100+20, 340+80-20+15, 100 + 40 + 60 + 40 +60+20, 340+80+60+40+40+20+15, width=3, fill="white")129 self.make_canvas.create_rectangle(340+(40*3)+40 - 20, 340 + 80 - 20+15, 340+(40*3)+40 + 60 + 40 + 40+20+20, 340 + 80 + 60 + 40 + 40 + 20+15, width=3, fill="white")130 # Left up square inside box made131 self.make_canvas.create_rectangle(100+40, 15+40, 100+40+40, 15+40+40, width=3, fill="red")132 self.make_canvas.create_rectangle(100+40+60+60, 15 + 40, 100+40+60+40+60, 15 + 40 + 40, width=3, fill="red")133 self.make_canvas.create_rectangle(100 + 40, 15 + 40+100, 100 + 40 + 40, 15 + 40 + 40+100, width=3, fill="red")134 self.make_canvas.create_rectangle(100 + 40 + 60 + 60, 15 + 40+100, 100 + 40 + 60 + 40 +60, 15 + 40 + 40+100, width=3, fill="red")135 # Right up square inside box made136 self.make_canvas.create_rectangle(340+(40*3)+40, 15 + 40, 340+(40*3)+40 + 40, 15 + 40 + 40, width=3, fill="#00FF00")137 self.make_canvas.create_rectangle(340+(40*3)+40+ 60 + 40+20, 15 + 40, 340+(40*3)+40 + 60 + 40 + 40+20, 15 + 40 + 40, width=3, fill="#00FF00")138 self.make_canvas.create_rectangle(340+(40*3)+40, 15 + 40 + 100, 340+(40*3)+40 + 40, 15 + 40 + 40 + 100, width=3, fill="#00FF00")139 self.make_canvas.create_rectangle(340+(40*3)+40+ 60 + 40+20, 15 + 40 + 100, 340+(40*3)+40 + 60 + 40 + 40+20, 15 + 40 + 40 + 100, width=3, fill="#00FF00")140 # Left down square inside box made141 self.make_canvas.create_rectangle(100 + 40, 340+80+15, 100 + 40 + 40, 340+80+40+15, width=3, fill="#04d9ff")142 self.make_canvas.create_rectangle(100 + 40 + 60 + 40+20, 340+80+15, 100 + 40 + 60 + 40 + 40+20, 340+80+40+15, width=3, fill="#04d9ff")143 self.make_canvas.create_rectangle(100 + 40, 340+80+60+40+15, 100 + 40 + 40, 340+80+60+40+40+15, width=3, fill="#04d9ff")144 self.make_canvas.create_rectangle(100 + 40 + 60 + 40+20, 340+80+60+40+15, 100 + 40 + 60 + 40 + 40+20, 340+80+60+40+40+15, width=3, fill="#04d9ff")145 # Right down square inside box made146 self.make_canvas.create_rectangle(340 + (40 * 3) + 40, 340+80+15, 340 + (40 * 3) + 40 + 40, 340+80+40+15, width=3, fill="yellow")147 self.make_canvas.create_rectangle(340 + (40 * 3) + 40 + 60 + 40+20, 340+80+15, 340 + (40 * 3) + 40 + 60 + 40 + 40+20, 340+80+40+15, width=3, fill="yellow")148 self.make_canvas.create_rectangle(340 + (40 * 3) + 40, 340+80+60+40+15, 340 + (40 * 3) + 40 + 40,340+80+60+40+40+15, width=3, fill="yellow")149 self.make_canvas.create_rectangle(340 + (40 * 3) + 40 + 60 + 40+20, 340+80+60+40+15,340 + (40 * 3) + 40 + 60 + 40 + 40+20, 340+80+60+40+40+15, width=3, fill="yellow")150 # sky_blue start position151 self.make_canvas.create_rectangle(100+240,340+(40*5)-5,100+240+40,340+(40*6)-5,fill="#04d9ff",width=3)152 # Red start position153 self.make_canvas.create_rectangle(100 + 40, 15+(40*6), 100 +40 + 40, 15+(40*6)+40, fill="red", width=3)154 # Green start position155 self.make_canvas.create_rectangle(100 + (40*8), 15 + 40, 100 +(40*9), 15 + 40+ 40, fill="#00FF00", width=3)156 # Yellow start position157 self.make_canvas.create_rectangle(100 + (40 * 6)+(40*3)+(40*4), 15 + (40*8), 100 + (40 * 6)+(40*3)+(40*5), 15 + (40*9), fill="yellow", width=3)158 # Traingle in middle159 self.make_canvas.create_polygon(100+240, 15+240, 100+240+60, 15+240+60, 100+240, 15+240+(40*3), width=3,fill="red",outline="black")160 self.make_canvas.create_polygon(100 + 240+(40*3), 15 + 240, 100 + 240 + 60, 15 + 240 + 60, 100 + 240+(40*3), 15 + 240 + (40 * 3), width=3, fill="yellow",outline="black")161 self.make_canvas.create_polygon(100 + 240, 15 + 240, 100 + 240 + 60, 15 + 240 + 60, 100 + 240 + (40 * 3), 15 + 240, width=3, fill="#00FF00",outline="black")162 self.make_canvas.create_polygon(100 + 240, 15 + 240+(40*3), 100 + 240 + 60, 15 + 240 + 60, 100 + 240 + (40 * 3), 15 + 240+(40*3), width=3, fill="#04d9ff",outline="black")163 # Make coin for red left up block164 red_1_coin = self.make_canvas.create_oval(100+40, 15+40, 100+40+40, 15+40+40, width=3, fill="red", outline="black")165 red_2_coin = self.make_canvas.create_oval(100+40+60+60, 15 + 40, 100+40+60+60+40, 15 + 40 + 40, width=3, fill="red", outline="black")166 red_3_coin = self.make_canvas.create_oval(100 + 40 + 60 + 60, 15 + 40 + 100, 100 + 40 + 60 + 60 + 40, 15 + 40 + 40 + 100, width=3, fill="red", outline="black")167 red_4_coin = self.make_canvas.create_oval(100 + 40, 15 + 40+100, 100 + 40 + 40, 15 + 40 + 40+100, width=3,fill="red", outline="black")168 self.made_red_coin.append(red_1_coin)169 self.made_red_coin.append(red_2_coin)170 self.made_red_coin.append(red_3_coin)171 self.made_red_coin.append(red_4_coin)172 # Make coin under number label for red left up block173 red_1_label = Label(self.make_canvas, text="1", font=("Arial", 15, "bold"), bg="red", fg="black")174 red_1_label.place(x=100 + 40 + 10, y=15 + 40 + 5)175 red_2_label = Label(self.make_canvas, text="2", font=("Arial", 15, "bold"), bg="red", fg="black")176 red_2_label.place(x=100 + 40 + 60 + 60 + 10, y=15 + 40 + 5)177 red_3_label = Label(self.make_canvas, text="3", font=("Arial", 15, "bold"), bg="red", fg="black")178 red_3_label.place(x=100 + 40 + 60 + 60 + 10, y=15 + 40 + 100 + 5)179 red_4_label = Label(self.make_canvas, text="4", font=("Arial", 15, "bold"), bg="red", fg="black")180 red_4_label.place(x=100 + 40 + 10, y=15 + 40 + 100 + 5)181 self.red_number_label.append(red_1_label)182 self.red_number_label.append(red_2_label)183 self.red_number_label.append(red_3_label)184 self.red_number_label.append(red_4_label)185 # Make coin for green right up block186 green_1_coin = self.make_canvas.create_oval(340+(40*3)+40, 15 + 40, 340+(40*3)+40 + 40, 15 + 40 + 40, width=3, fill="#00FF00", outline="black")187 green_2_coin = self.make_canvas.create_oval(340+(40*3)+40+ 60 + 40+20, 15 + 40, 340+(40*3)+40 + 60 + 40 + 40+20, 15 + 40 + 40, width=3, fill="#00FF00", outline="black")188 green_3_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40 + 60 + 40 + 20, 15 + 40 + 100, 340 + (40 * 3) + 40 + 60 + 40 + 40 + 20, 15 + 40 + 40 + 100, width=3, fill="#00FF00", outline="black")189 green_4_coin = self.make_canvas.create_oval(340+(40*3)+40, 15 + 40 + 100, 340+(40*3)+40 + 40, 15 + 40 + 40 + 100, width=3, fill="#00FF00", outline="black")190 self.made_green_coin.append(green_1_coin)191 self.made_green_coin.append(green_2_coin)192 self.made_green_coin.append(green_3_coin)193 self.made_green_coin.append(green_4_coin)194 # Make coin under number label for green right up block195 green_1_label = Label(self.make_canvas, text="1", font=("Arial", 15, "bold"), bg="#00FF00", fg="black")196 green_1_label.place(x=340 + (40 * 3) + 40 + 10, y=15 + 40 + 5)197 green_2_label = Label(self.make_canvas, text="2", font=("Arial", 15, "bold"), bg="#00FF00", fg="black")198 green_2_label.place(x=340 + (40 * 3) + 40 + 40 + 60 + 30, y=15 + 40 + 5)199 green_3_label = Label(self.make_canvas, text="3", font=("Arial", 15, "bold"), bg="#00FF00", fg="black")200 green_3_label.place(x=340 + (40 * 3) + 40 + 40 + 60 + 30, y=15 + 40 + 100 + 5)201 green_4_label = Label(self.make_canvas, text="4", font=("Arial", 15, "bold"), bg="#00FF00", fg="black")202 green_4_label.place(x=340 + (40 * 3) + 40 + 10, y=15 + 40 + 100 + 5)203 self.green_number_label.append(green_1_label)204 self.green_number_label.append(green_2_label)205 self.green_number_label.append(green_3_label)206 self.green_number_label.append(green_4_label)207 # Make coin for sky_blue left down block208 sky_blue_1_coin = self.make_canvas.create_oval(100 + 40, 340+80+15, 100 + 40 + 40, 340+80+40+15, width=3, fill="#04d9ff", outline="black")209 sky_blue_2_coin = self.make_canvas.create_oval(100 + 40 + 60 + 40+20, 340+80+15, 100 + 40 + 60 + 40 + 40+20, 340+80+40+15, width=3, fill="#04d9ff", outline="black")210 sky_blue_3_coin = self.make_canvas.create_oval(100 + 40 + 60 + 40 + 20, 340 + 80 + 60 + 40 + 15, 100 + 40 + 60 + 40 + 40 + 20, 340 + 80 + 60 + 40 + 40 + 15, width=3, fill="#04d9ff", outline="black")211 sky_blue_4_coin = self.make_canvas.create_oval( 100 + 40, 340+80+60+40+15, 100 + 40 + 40, 340+80+60+40+40+15, width=3, fill="#04d9ff", outline="black")212 self.made_sky_blue_coin.append(sky_blue_1_coin)213 self.made_sky_blue_coin.append(sky_blue_2_coin)214 self.made_sky_blue_coin.append(sky_blue_3_coin)215 self.made_sky_blue_coin.append(sky_blue_4_coin)216 # Make coin under number label for sky_blue left down block217 sky_blue_1_label = Label(self.make_canvas, text="1", font=("Arial", 15, "bold"), bg="#04d9ff", fg="black")218 sky_blue_1_label.place(x=100 + 40 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 10)219 sky_blue_2_label = Label(self.make_canvas, text="2", font=("Arial", 15, "bold"), bg="#04d9ff", fg="black")220 sky_blue_2_label.place(x=100 + 40 + 60 + 60 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 10)221 sky_blue_3_label = Label(self.make_canvas, text="3", font=("Arial", 15, "bold"), bg="#04d9ff", fg="black")222 sky_blue_3_label.place(x=100 + 40 + 60 + 60 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 60 + 40 + 10)223 sky_blue_4_label = Label(self.make_canvas, text="4", font=("Arial", 15, "bold"), bg="#04d9ff", fg="black")224 sky_blue_4_label.place(x=100 + 40 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 60 + 40 + 10)225 self.sky_blue_number_label.append(sky_blue_1_label)226 self.sky_blue_number_label.append(sky_blue_2_label)227 self.sky_blue_number_label.append(sky_blue_3_label)228 self.sky_blue_number_label.append(sky_blue_4_label)229 # Make coin for yellow right down block230 yellow_1_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40, 340+80+15, 340 + (40 * 3) + 40 + 40, 340+80+40+15, width=3, fill="yellow", outline="black")231 yellow_2_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40 + 60 + 40 + 20, 340+80+15, 340 + (40 * 3) + 40 + 60 + 40 + 40+20, 340+80+40+15, width=3, fill="yellow", outline="black")232 yellow_3_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40 + 60 + 40 + 20, 340 + 80 + 60 + 40 + 15, 340 + (40 * 3) + 40 + 60 + 40 + 40 + 20, 340 + 80 + 60 + 40 + 40 + 15, width=3, fill="yellow", outline="black")233 yellow_4_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40, 340+80+60+40+15, 340 + (40 * 3) + 40 + 40,340+80+60+40+40+15, width=3, fill="yellow", outline="black")234 self.made_yellow_coin.append(yellow_1_coin)235 self.made_yellow_coin.append(yellow_2_coin)236 self.made_yellow_coin.append(yellow_3_coin)237 self.made_yellow_coin.append(yellow_4_coin)238 # Make coin under number label for yellow right down block239 yellow_1_label = Label(self.make_canvas, text="1", font=("Arial", 15, "bold"), bg="yellow", fg="black")240 yellow_1_label.place(x=340 + (40 * 3) + 40 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 10)241 yellow_2_label = Label(self.make_canvas, text="2", font=("Arial", 15, "bold"), bg="yellow", fg="black")242 yellow_2_label.place(x=340 + (40 * 3) + 40 + 40 + 60 + 30, y=30 + (40 * 6) + (40 * 3) + 40 + 10)243 yellow_3_label = Label(self.make_canvas, text="3", font=("Arial", 15, "bold"), bg="yellow", fg="black")244 yellow_3_label.place(x=340 + (40 * 3) + 40 + 40 + 60 + 30, y=30 + (40 * 6) + (40 * 3) + 40 + 100 + 10)245 yellow_4_label = Label(self.make_canvas, text="4", font=("Arial", 15, "bold"), bg="yellow", fg="black")246 yellow_4_label.place(x=340 + (40 * 3) + 40 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 100 + 10)247 self.yellow_number_label.append(yellow_1_label)248 self.yellow_number_label.append(yellow_2_label)249 self.yellow_number_label.append(yellow_3_label)250 self.yellow_number_label.append(yellow_4_label)251 # Make star safe zone252 """253 A254 L * B255 K * * * * * * C256 * *257 J * * D258 * *259 I* * * * * * E260 H * F261 G262 """263 # Right star264 common_x = 340+(40*6)+20265 common_y = 15+240+2266 # A B C D E F G H I J K L267 coord = [common_x,common_y, common_x+5,common_y+15, common_x+15,common_y+15, common_x+8,common_y+20, common_x+15,common_y+25, common_x+5,common_y+25, common_x,common_y+25+10, common_x-5,common_y+25, common_x-16,common_y+25, common_x-8,common_y+15+5, common_x-15,common_y+15, common_x-5,common_y+15]268 self.make_canvas.create_polygon(coord,width=3,fill="blue")269 # Up star270 common_x = 100+240+2+18271 common_y = 15 + (40*2) + 2272 # A B C D E F G H I J K L273 coord = [common_x, common_y, common_x + 5, common_y + 15, common_x + 15, common_y + 15, common_x + 8, common_y + 20, common_x + 15, common_y + 25, common_x + 5, common_y + 25, common_x, common_y + 25 + 10, common_x - 5, common_y + 25, common_x - 16, common_y + 25, common_x - 8,common_y + 15 + 5, common_x - 15,common_y + 15, common_x - 5,common_y + 15]274 self.make_canvas.create_polygon(coord, width=3, fill="blue")275 # Left star276 common_x = 100 + (40*2) + 2 +18277 common_y = 15 + 240+(40*2) + 2278 # A B C D E F G H I J K L279 coord = [common_x, common_y, common_x + 5, common_y + 15, common_x + 15, common_y + 15, common_x + 8,common_y + 20, common_x + 15, common_y + 25, common_x + 5, common_y + 25, common_x, common_y + 25 + 10, common_x - 5, common_y + 25, common_x - 16, common_y + 25, common_x - 8, common_y + 15 + 5, common_x - 15, common_y + 15, common_x - 5, common_y + 15]280 self.make_canvas.create_polygon(coord, width=3, fill="blue")281 # Down star282 common_x = 100 + 240 + (40*2) + 2 + 18283 common_y = 15 + (40 * 6) + (40*3)+(40*3)+2284 # A B C D E F G H I J K L285 coord = [common_x, common_y, common_x + 5, common_y + 15, common_x + 15, common_y + 15, common_x + 8, common_y + 20, common_x + 15, common_y + 25, common_x + 5, common_y + 25, common_x, common_y + 25 + 10, common_x - 5, common_y + 25, common_x - 16, common_y + 25, common_x - 8, common_y + 15 + 5, common_x - 15, common_y + 15, common_x - 5, common_y + 15]286 self.make_canvas.create_polygon(coord, width=3, fill="blue")287 # Total number of players: Control take at first288 def take_initial_control(self):289 for i in range(4):290 self.block_value_predict[i][1]['state'] = DISABLED291 # Make other window to control take292 top = Toplevel()293 top.geometry("600x150")294 top.maxsize(600,150)295 top.minsize(600,150)296 top.config(bg="orange")297 top.iconbitmap("Images/ludo_icon.ico")298 head = Label(top,text="-:Total number of players:- ",font=("Arial",25,"bold","italic"),bg="orange",fg="chocolate")299 head.place(x=70,y=30)300 take_entry = Entry(top,font=("Arial",18,"bold","italic"),relief=SUNKEN,bd=7,width=12)301 take_entry.place(x=150,y=80)302 take_entry.focus()303 def filtering():# Total player input value filtering304 response_take = self.input_filtering(take_entry.get())305 if response_take is True and int(take_entry.get())>1:306 for player_index in range(int(take_entry.get())):307 self.total_people_play.append(player_index)308 print(self.total_people_play)309 self.make_command()310 top.destroy()311 else:312 messagebox.showerror("Input Error", "Please input number of players between 2 and 4")313 submit_btn = Button(top,text="Submit",bg="black",fg="#00FF00",font=("Arial",13,"bold"),relief=RAISED,bd=8,command=filtering)314 submit_btn.place(x=350,y=80)315 top.mainloop()316 # Get block value after prediction based on probability317 def make_prediction(self,color_indicator):318 try:319 if color_indicator == "red":320 block_value_predict = self.block_value_predict[0]321 permanent_block_number = self.move_red_counter = randint(1, 6)322 elif color_indicator == "sky_blue":323 block_value_predict = self.block_value_predict[1]324 permanent_block_number = self.move_sky_blue_counter = randint(1, 6)325 elif color_indicator == "yellow":326 block_value_predict = self.block_value_predict[2]327 permanent_block_number = self.move_yellow_counter = randint(1, 6)328 else:329 block_value_predict = self.block_value_predict[3]330 permanent_block_number = self.move_green_counter = randint(1, 6)331 block_value_predict[1]['state'] = DISABLED332 # Illusion of coin floating333 temp_counter = 15334 while temp_counter>0:335 move_temp_counter = randint(1, 6)336 block_value_predict[0]['image'] = self.block_number_side[move_temp_counter - 1]337 self.window.update()338 time.sleep(0.1)339 temp_counter-=1340 print("Prediction result: ", permanent_block_number)341 # Permanent predicted value containing image set342 block_value_predict[0]['image'] = self.block_number_side[permanent_block_number-1]343 self.instructional_btn_customization_based_on_current_situation(color_indicator,permanent_block_number,block_value_predict)344 except:345 print("Force stop error")346 def instructional_btn_customization_based_on_current_situation(self,color_indicator,permanent_block_number,block_value_predict):347 if color_indicator == "red":348 temp_coin_position = self.red_coin_position349 elif color_indicator == "green":350 temp_coin_position = self.green_coin_position351 elif color_indicator == "yellow":352 temp_coin_position = self.yellow_coin_position353 else:354 temp_coin_position = self.sky_blue_coin_position355 all_in = 1356 for i in range(4):357 if temp_coin_position[i] == -1:358 all_in = 1359 else:360 all_in = 0361 break362 if permanent_block_number == 6:363 self.six_counter += 1364 else:365 self.six_counter = 0366 if ((all_in == 1 and permanent_block_number == 6) or (all_in==0)) and self.six_counter<3:367 permission = 1368 if color_indicator == "red":369 temp = self.red_coord_store370 elif color_indicator == "green":371 temp = self.green_coord_store372 elif color_indicator == "yellow":373 temp = self.yellow_coord_store374 else:375 temp = self.sky_blue_coord_store376 if permanent_block_number<6:377 if self.six_with_overlap == 1:378 self.time_for-=1379 self.six_with_overlap=0380 for i in range(4):381 if temp[i] == -1:382 permission=0383 elif temp[i]>100:384 if temp[i]+permanent_block_number<=106:385 permission=1386 break387 else:388 permission=0389 else:390 permission=1391 break392 else:393 for i in range(4):394 if temp[i]>100:395 if temp[i] + permanent_block_number <= 106:396 permission = 1397 break398 else:399 permission = 0400 else:401 permission = 1402 break403 if permission == 0:404 self.make_command()405 else:406 block_value_predict[3]['state'] = NORMAL# Give btn activation407 block_value_predict[1]['state'] = DISABLED# Predict btn deactivation408 else:409 block_value_predict[1]['state'] = NORMAL# Predict btn activation410 if self.six_with_overlap == 1:411 self.time_for -= 1412 self.six_with_overlap = 0413 self.make_command()414 if permanent_block_number == 6 and self.six_counter<3 and block_value_predict[3]['state'] == NORMAL:415 self.time_for-=1416 else:417 self.six_counter=0418 # Player Scope controller419 def make_command(self):420 if self.time_for == -1:421 pass422 else:423 self.block_value_predict[self.total_people_play[self.time_for]][1]['state'] = DISABLED424 if self.time_for == len(self.total_people_play)-1:425 self.time_for = -1426 self.time_for+=1427 self.block_value_predict[self.total_people_play[self.time_for]][1]['state'] = NORMAL428 def instruction_btn_red(self):429 block_predict_red = Label(self.make_canvas,image=self.block_number_side[0])430 block_predict_red.place(x=45,y=15)431 predict_red = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Predict", font=("Arial", 8, "bold"), command=lambda: self.make_prediction("red"))432 predict_red.place(x=37, y=15 + 40)433 entry_take_red = Entry(self.make_canvas,bg="white",fg="blue",font=("Arial",25,"bold","italic"),width=2,relief=SUNKEN,bd=5)434 entry_take_red.place(x=40,y=15+80)435 final_move = Button(self.make_canvas,bg="black",fg="#00FF00",relief=RAISED,bd=5,text="Give",font=("Arial",8,"bold"),command=lambda: self.main_controller("red",entry_take_red.get()),state=DISABLED)436 final_move.place(x=42,y=15+140)437 Label(self.make_canvas,text="Player 1",bg="#4d4dff",fg="gold",font=("Arial",15,"bold")).place(x=15,y=15+140+40)438 self.store_instructional_btn(block_predict_red,predict_red,entry_take_red,final_move)439 def instruction_btn_sky_blue(self):440 block_predict_sky_blue = Label(self.make_canvas, image=self.block_number_side[0])441 block_predict_sky_blue.place(x=45, y=15+(40*6+40*3)+10)442 predict_sky_blue = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Predict",font=("Arial", 8, "bold"), command=lambda: self.make_prediction("sky_blue"))443 predict_sky_blue.place(x=37, y=15+(40*6+40*3)+40 + 10)444 entry_take_sky_blue = Entry(self.make_canvas, bg="white", fg="blue", font=("Arial", 25, "bold", "italic"), width=2,relief=SUNKEN, bd=5)445 entry_take_sky_blue.place(x=40, y=15+(40*6+40*3)+40 + 50)446 final_move = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Give", font=("Arial", 8, "bold"),command=lambda: self.main_controller("sky_blue",entry_take_sky_blue.get()),state=DISABLED)447 final_move.place(x=42, y=15+(40*6+40*3)+40 + 110)448 Label(self.make_canvas, text="Player 2", bg="#4d4dff", fg="gold", font=("Arial", 15, "bold")).place(x=15,y=15+(40*6+40*3)+40 + 110+ 40)449 self.store_instructional_btn(block_predict_sky_blue, predict_sky_blue, entry_take_sky_blue, final_move)450 def instruction_btn_yellow(self):451 block_predict_yellow = Label(self.make_canvas, image=self.block_number_side[0])452 block_predict_yellow.place(x=100 + (40 * 6 + 40 * 3 + 40 * 6 + 10)+10, y=15 + (40 * 6 + 40 * 3) + 10)453 predict_yellow = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Predict",font=("Arial", 8, "bold"), command=lambda: self.make_prediction("yellow"))454 predict_yellow.place(x=100 + (40 * 6 + 40 * 3 + 40 * 6 + 2)+10, y=15 + (40 * 6 + 40 * 3) + 40 + 10)455 entry_take_yellow = Entry(self.make_canvas, bg="white", fg="blue", font=("Arial", 25, "bold", "italic"),width=2, relief=SUNKEN, bd=5)456 entry_take_yellow.place(x=100 + (40 * 6 + 40 * 3 + 40 * 6 + 2)+13, y=15 + (40 * 6 + 40 * 3) + 40 + 50)457 final_move = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Give",font=("Arial", 8, "bold"),command=lambda: self.main_controller("yellow",entry_take_yellow.get()),state=DISABLED)458 final_move.place(x=100 + (40 * 6 + 40 * 3 + 40 * 6 + 2)+17, y=15 + (40 * 6 + 40 * 3) + 40 + 110)459 Label(self.make_canvas, text="Player 3", bg="#4d4dff", fg="gold", font=("Arial", 15, "bold")).place(x=100 + (40 * 6 + 40 * 3 + 40 * 6 + 3),y=15 + (40 * 6 + 40 * 3) + 40 + 110 + 40)460 self.store_instructional_btn(block_predict_yellow, predict_yellow, entry_take_yellow, final_move)461 def instruction_btn_green(self):462 block_predict_green = Label(self.make_canvas, image=self.block_number_side[0])463 block_predict_green.place(x=100+(40*6+40*3+40*6+10)+10, y=15)464 predict_green = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Predict", font=("Arial", 8, "bold"), command=lambda: self.make_prediction("green"))465 predict_green.place(x=100+(40*6+40*3+40*6+2)+10, y=15 + 40)466 entry_take_green = Entry(self.make_canvas, bg="white", fg="blue", font=("Arial", 25, "bold", "italic"), width=2, relief=SUNKEN, bd=5)467 entry_take_green.place(x=100+(40*6+40*3+40*6+2)+13, y=15 + 80)468 final_move = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Give",font=("Arial", 8, "bold"),command=lambda: self.main_controller("green",entry_take_green.get()),state=DISABLED)469 final_move.place(x=100+(40*6+40*3+40*6+2)+17, y=15 + 140)470 Label(self.make_canvas, text="Player 4", bg="#4d4dff", fg="gold", font=("Arial", 15, "bold")).place(x=100+(40*6+40*3+40*6+3), y=15 + 140+40)471 self.store_instructional_btn(block_predict_green, predict_green, entry_take_green, final_move)472 def store_instructional_btn(self, block_indicator, predictor, entry_controller, give_finally):473 temp = []474 temp.append(block_indicator)475 temp.append(predictor)476 temp.append(entry_controller)477 temp.append(give_finally)478 self.block_value_predict.append(temp)479 # self.block_value_predict[0] = red instruction information480 # self.block_value_predict[1] = sky_blue instruction information481 # self.block_value_predict[2] = yellow instruction information482 # self.block_value_predict[3] = green instruction information483 # self.block_value_predict[something][1] = Predict btn484 # self.block_value_predict[something][3] = Give btn485 def red_circle_start_position(self, coin_number):486 self.make_canvas.delete(self.made_red_coin[int(coin_number)-1])487 self.made_red_coin[int(coin_number)-1] = self.make_canvas.create_oval(100 + 40, 15+(40*6), 100 +40 + 40, 15+(40*6)+40, fill="red", width=3, outline="black")488 self.red_number_label[int(coin_number)-1].place_forget()489 red_start_label_x = 100 + 40 + 10490 red_start_label_y = 15 + (40 * 6) + 5491 self.red_number_label[int(coin_number)-1].place(x=red_start_label_x, y=red_start_label_y)492 self.red_coin_position[int(coin_number)-1] = 1493 self.window.update()494 time.sleep(0.2)495 def green_circle_start_position(self,coin_number):496 self.make_canvas.delete(self.made_green_coin[int(coin_number)-1])497 self.made_green_coin[int(coin_number)-1] = self.make_canvas.create_oval(100 + (40*8), 15 + 40, 100 +(40*9), 15 + 40+ 40, fill="#00FF00", width=3)498 self.green_number_label[int(coin_number)-1].place_forget()499 green_start_label_x = 100 + (40*8) + 10500 green_start_label_y = 15 + 40 + 5501 self.green_number_label[int(coin_number)-1].place(x=green_start_label_x, y=green_start_label_y)502 self.green_coin_position[int(coin_number)-1] = 14503 self.window.update()504 time.sleep(0.2)505 def yellow_circle_start_position(self,coin_number):506 self.make_canvas.delete(self.made_yellow_coin[int(coin_number)-1])507 self.made_yellow_coin[int(coin_number)-1] = self.make_canvas.create_oval(100 + (40 * 6)+(40*3)+(40*4), 15 + (40*8), 100 + (40 * 6)+(40*3)+(40*5), 15 + (40*9), fill="yellow", width=3)508 self.yellow_number_label[int(coin_number)-1].place_forget()509 yellow_start_label_x = 100 + (40 * 6)+(40*3)+(40*4) + 10510 yellow_start_label_y = 15 + (40*8) + 5511 self.yellow_number_label[int(coin_number) - 1].place(x=yellow_start_label_x, y=yellow_start_label_y)512 self.yellow_coin_position[int(coin_number) - 1] = 27513 self.window.update()514 time.sleep(0.2)515 def sky_blue_circle_start_position(self,coin_number):516 self.make_canvas.delete(self.made_sky_blue_coin[int(coin_number)-1])517 self.made_sky_blue_coin[int(coin_number)-1] = self.make_canvas.create_oval(100+240,340+(40*5)-5,100+240+40,340+(40*6)-5,fill="#04d9ff",width=3)518 self.sky_blue_number_label[int(coin_number)-1].place_forget()519 sky_blue_start_label_x = 100+240 + 10520 sky_blue_start_label_y = 340+(40*5)-5 + 5521 self.sky_blue_number_label[int(coin_number) - 1].place(x=sky_blue_start_label_x, y=sky_blue_start_label_y)522 self.sky_blue_coin_position[int(coin_number) - 1] = 40523 self.window.update()524 time.sleep(0.2)525 def main_controller(self, color_coin, coin_number):526 processing_result = self.input_filtering(coin_number)# Value filtering527 if processing_result is True:528 pass529 else:530 messagebox.showerror("Wrong input number","Please input the coin number between 1 to 4")531 return532 if color_coin == "red":533 self.block_value_predict[0][3]['state'] = DISABLED534 if self.move_red_counter == 106:535 messagebox.showwarning("Destination reached","Reached at the destination")536 elif self.red_coin_position[int(coin_number)-1] == -1 and self.move_red_counter == 6:537 self.red_circle_start_position(coin_number)538 self.red_coord_store[int(coin_number) - 1] = 1539 elif self.red_coin_position[int(coin_number)-1] > -1:540 take_coord = self.make_canvas.coords(self.made_red_coin[int(coin_number)-1])541 red_start_label_x = take_coord[0] + 10542 red_start_label_y = take_coord[1] + 5543 self.red_number_label[int(coin_number) - 1].place(x=red_start_label_x, y=red_start_label_y)544 if self.red_coin_position[int(coin_number)-1]+self.move_red_counter<=106:545 self.red_coin_position[int(coin_number)-1] = self.motion_of_coin(self.red_coin_position[int(coin_number) - 1],self.made_red_coin[int(coin_number)-1],self.red_number_label[int(coin_number)-1],red_start_label_x,red_start_label_y,"red",self.move_red_counter)546 else:547 messagebox.showerror("Not possible","Sorry, not permitted")548 self.block_value_predict[0][3]['state'] = NORMAL549 return550 if self.red_coin_position[int(coin_number)-1]==22 or self.red_coin_position[int(coin_number)-1]==9 or self.red_coin_position[int(coin_number)-1]==48 or self.red_coin_position[int(coin_number)-1]==35 or self.red_coin_position[int(coin_number)-1]==14 or self.red_coin_position[int(coin_number)-1]==27 or self.red_coin_position[int(coin_number)-1]==40:551 pass552 else:553 if self.red_coin_position[int(coin_number) - 1] < 100:554 self.coord_overlap(self.red_coin_position[int(coin_number)-1],color_coin, self.move_red_counter)555 self.red_coord_store[int(coin_number)-1] = self.red_coin_position[int(coin_number)-1]556 else:557 messagebox.showerror("Wrong choice","Sorry, Your coin in not permitted to travel")558 self.block_value_predict[0][3]['state'] = NORMAL559 return560 self.block_value_predict[0][1]['state'] = NORMAL561 elif color_coin == "green":562 self.block_value_predict[3][3]['state'] = DISABLED563 if self.move_green_counter == 106:564 messagebox.showwarning("Destination reached","Reached at the destination")565 elif self.green_coin_position[int(coin_number) - 1] == -1 and self.move_green_counter == 6:566 self.green_circle_start_position(coin_number)567 self.green_coord_store[int(coin_number) - 1] = 14568 elif self.green_coin_position[int(coin_number) - 1] > -1:569 take_coord = self.make_canvas.coords(self.made_green_coin[int(coin_number) - 1])570 green_start_label_x = take_coord[0] + 10571 green_start_label_y = take_coord[1] + 5572 self.green_number_label[int(coin_number) - 1].place(x=green_start_label_x, y=green_start_label_y)573 if self.green_coin_position[int(coin_number) - 1] + self.move_green_counter <= 106:574 self.green_coin_position[int(coin_number) - 1] = self.motion_of_coin(self.green_coin_position[int(coin_number) - 1], self.made_green_coin[int(coin_number) - 1], self.green_number_label[int(coin_number) - 1], green_start_label_x, green_start_label_y, "green", self.move_green_counter)575 else:576 messagebox.showerror("Not possible","No path available")577 self.block_value_predict[3][3]['state'] = NORMAL578 return579 if self.green_coin_position[int(coin_number)-1]==22 or self.green_coin_position[int(coin_number)-1]==9 or self.green_coin_position[int(coin_number)-1]==48 or self.green_coin_position[int(coin_number)-1]==35 or self.green_coin_position[int(coin_number)-1]==1 or self.green_coin_position[int(coin_number)-1]==27 or self.green_coin_position[int(coin_number)-1]==40:580 pass581 else:582 if self.green_coin_position[int(coin_number) - 1] < 100:583 self.coord_overlap(self.green_coin_position[int(coin_number) - 1],color_coin, self.move_green_counter)584 self.green_coord_store[int(coin_number) - 1] = self.green_coin_position[int(coin_number) - 1]585 else:586 messagebox.showerror("Wrong choice", "Sorry, Your coin in not permitted to travel")587 self.block_value_predict[3][3]['state'] = NORMAL588 return589 self.block_value_predict[3][1]['state'] = NORMAL590 elif color_coin == "yellow":591 self.block_value_predict[2][3]['state'] = DISABLED592 if self.move_yellow_counter == 106:593 messagebox.showwarning("Destination reached","Reached at the destination")594 elif self.yellow_coin_position[int(coin_number) - 1] == -1 and self.move_yellow_counter == 6:595 self.yellow_circle_start_position(coin_number)596 self.yellow_coord_store[int(coin_number) - 1] = 27597 elif self.yellow_coin_position[int(coin_number) - 1] > -1:598 take_coord = self.make_canvas.coords(self.made_yellow_coin[int(coin_number) - 1])599 yellow_start_label_x = take_coord[0] + 10600 yellow_start_label_y = take_coord[1] + 5601 self.yellow_number_label[int(coin_number) - 1].place(x=yellow_start_label_x, y=yellow_start_label_y)602 if self.yellow_coin_position[int(coin_number) - 1] + self.move_yellow_counter <= 106:603 self.yellow_coin_position[int(coin_number) - 1] = self.motion_of_coin(self.yellow_coin_position[int(coin_number) - 1], self.made_yellow_coin[int(coin_number) - 1], self.yellow_number_label[int(coin_number) - 1], yellow_start_label_x, yellow_start_label_y, "yellow", self.move_yellow_counter)604 else:605 messagebox.showerror("Not possible","No path available")606 self.block_value_predict[2][3]['state'] = NORMAL607 return608 if self.yellow_coin_position[int(coin_number)-1]==22 or self.yellow_coin_position[int(coin_number)-1]==9 or self.yellow_coin_position[int(coin_number)-1]==48 or self.yellow_coin_position[int(coin_number)-1]==35 or self.yellow_coin_position[int(coin_number)-1]==1 or self.yellow_coin_position[int(coin_number)-1]==14 or self.yellow_coin_position[int(coin_number)-1]==40:609 pass610 else:611 if self.yellow_coin_position[int(coin_number) - 1] < 100:612 self.coord_overlap(self.yellow_coin_position[int(coin_number) - 1],color_coin, self.move_yellow_counter)613 self.yellow_coord_store[int(coin_number) - 1] = self.yellow_coin_position[int(coin_number) - 1]614 else:615 messagebox.showerror("Wrong choice", "Sorry, Your coin in not permitted to travel")616 self.block_value_predict[2][3]['state'] = NORMAL617 return618 self.block_value_predict[2][1]['state'] = NORMAL619 elif color_coin == "sky_blue":620 self.block_value_predict[1][3]['state'] = DISABLED621 if self.move_red_counter == 106:622 messagebox.showwarning("Destination reached","Reached at the destination")623 elif self.sky_blue_coin_position[int(coin_number) - 1] == -1 and self.move_sky_blue_counter == 6:624 self.sky_blue_circle_start_position(coin_number)625 self.sky_blue_coord_store[int(coin_number) - 1] = 40626 elif self.sky_blue_coin_position[int(coin_number) - 1] > -1:627 take_coord = self.make_canvas.coords(self.made_sky_blue_coin[int(coin_number) - 1])628 sky_blue_start_label_x = take_coord[0] + 10629 sky_blue_start_label_y = take_coord[1] + 5630 self.sky_blue_number_label[int(coin_number) - 1].place(x=sky_blue_start_label_x, y=sky_blue_start_label_y)631 if self.sky_blue_coin_position[int(coin_number) - 1] + self.move_sky_blue_counter <= 106:632 self.sky_blue_coin_position[int(coin_number) - 1] = self.motion_of_coin(self.sky_blue_coin_position[int(coin_number) - 1], self.made_sky_blue_coin[int(coin_number) - 1], self.sky_blue_number_label[int(coin_number) - 1], sky_blue_start_label_x, sky_blue_start_label_y, "sky_blue", self.move_sky_blue_counter)633 else:634 messagebox.showerror("Not possible","No path available")635 self.block_value_predict[1][3]['state'] = NORMAL636 return637 if self.sky_blue_coin_position[int(coin_number)-1]==22 or self.sky_blue_coin_position[int(coin_number)-1]==9 or self.sky_blue_coin_position[int(coin_number)-1]==48 or self.sky_blue_coin_position[int(coin_number)-1]==35 or self.sky_blue_coin_position[int(coin_number)-1]==1 or self.sky_blue_coin_position[int(coin_number)-1]==14 or self.sky_blue_coin_position[int(coin_number)-1]==27:638 pass639 else:640 if self.sky_blue_coin_position[int(coin_number) - 1] < 100:641 self.coord_overlap(self.sky_blue_coin_position[int(coin_number) - 1],color_coin, self.move_sky_blue_counter)642 self.sky_blue_coord_store[int(coin_number) - 1] = self.sky_blue_coin_position[int(coin_number) - 1]643 else:644 messagebox.showerror("Wrong choice", "Sorry, Your coin in not permitted to travel")645 self.block_value_predict[1][3]['state'] = NORMAL646 return647 self.block_value_predict[1][1]['state'] = NORMAL648 print(self.red_coord_store)649 print(self.green_coord_store)650 print(self.yellow_coord_store)651 print(self.sky_blue_coord_store)652 permission_granted_to_proceed = True653 if color_coin == "red" and self.red_coin_position[int(coin_number)-1] == 106:654 permission_granted_to_proceed = self.check_winner_and_runner(color_coin)655 elif color_coin == "green" and self.green_coin_position[int(coin_number)-1] == 106:656 permission_granted_to_proceed = self.check_winner_and_runner(color_coin)657 elif color_coin == "yellow" and self.yellow_coin_position[int(coin_number)-1] == 106:658 permission_granted_to_proceed = self.check_winner_and_runner(color_coin)659 elif color_coin == "sky_blue" and self.sky_blue_coin_position[int(coin_number)-1] == 106:660 permission_granted_to_proceed = self.check_winner_and_runner(color_coin)661 if permission_granted_to_proceed:# if that is False, Game is over and not proceed more662 self.make_command()663 def motion_of_coin(self,counter_coin,specific_coin,number_label,number_label_x ,number_label_y,color_coin,path_counter):664 number_label.place(x=number_label_x,y=number_label_y)665 while True:666 if path_counter == 0:667 break668 elif (counter_coin == 51 and color_coin == "red") or (counter_coin==12 and color_coin == "green") or (counter_coin == 25 and color_coin == "yellow") or (counter_coin == 38 and color_coin == "sky_blue") or counter_coin>=100:669 if counter_coin<100:670 counter_coin=100671 counter_coin = self.under_room_traversal_control(specific_coin, number_label, number_label_x, number_label_y, path_counter, counter_coin, color_coin)672 if counter_coin == 106:673 messagebox.showinfo("Destination reached","Congrats! You now at the destination")674 if path_counter == 6:675 self.six_with_overlap = 1676 else:677 self.time_for -= 1678 break679 counter_coin += 1680 path_counter -=1681 number_label.place_forget()682 print(counter_coin)683 if counter_coin<=5:684 self.make_canvas.move(specific_coin, 40, 0)685 number_label_x+=40686 elif counter_coin == 6:687 self.make_canvas.move(specific_coin, 40, -40)688 number_label_x += 40689 number_label_y-=40690 elif 6< counter_coin <=11:691 self.make_canvas.move(specific_coin, 0, -40)692 number_label_y -= 40693 elif counter_coin <=13:694 self.make_canvas.move(specific_coin, 40, 0)695 number_label_x += 40696 elif counter_coin <=18:697 self.make_canvas.move(specific_coin, 0, 40)698 number_label_y += 40699 elif counter_coin == 19:700 self.make_canvas.move(specific_coin, 40, 40)701 number_label_x += 40702 number_label_y += 40703 elif counter_coin <=24:704 self.make_canvas.move(specific_coin, 40, 0)705 number_label_x += 40706 elif counter_coin <=26:707 self.make_canvas.move(specific_coin, 0, 40)708 number_label_y += 40709 elif counter_coin <=31:710 self.make_canvas.move(specific_coin, -40, 0)711 number_label_x -= 40712 elif counter_coin == 32:713 self.make_canvas.move(specific_coin, -40, 40)714 number_label_x -= 40715 number_label_y += 40716 elif counter_coin <= 37:717 self.make_canvas.move(specific_coin, 0, 40)718 number_label_y += 40719 elif counter_coin <= 39:720 self.make_canvas.move(specific_coin, -40, 0)721 number_label_x -= 40722 elif counter_coin <= 44:723 self.make_canvas.move(specific_coin, 0, -40)724 number_label_y -= 40725 elif counter_coin == 45:726 self.make_canvas.move(specific_coin, -40, -40)727 number_label_x -= 40728 number_label_y -= 40729 elif counter_coin <= 50:730 self.make_canvas.move(specific_coin, -40, 0)731 number_label_x -= 40732 elif 50< counter_coin <=52:733 self.make_canvas.move(specific_coin, 0, -40)734 number_label_y -= 40735 elif counter_coin == 53:736 self.make_canvas.move(specific_coin, 40, 0)737 number_label_x += 40738 counter_coin = 1739 number_label.place_forget()740 number_label.place(x=number_label_x, y=number_label_y)741 self.window.update()742 time.sleep(0.2)743 return counter_coin744 # For same position, previous coin deleted and set to the room745 def coord_overlap(self, counter_coin, color_coin, path_to_traverse_before_overlap):746 if color_coin!="red":747 for take_coin_number in range(len(self.red_coord_store)):748 if self.red_coord_store[take_coin_number] == counter_coin:749 if path_to_traverse_before_overlap == 6:750 self.six_with_overlap=1751 else:752 self.time_for-=1753 self.make_canvas.delete(self.made_red_coin[take_coin_number])754 self.red_number_label[take_coin_number].place_forget()755 self.red_coin_position[take_coin_number] = -1756 self.red_coord_store[take_coin_number] = -1757 if take_coin_number == 0:758 remade_coin = self.make_canvas.create_oval(100+40, 15+40, 100+40+40, 15+40+40, width=3, fill="red", outline="black")759 self.red_number_label[take_coin_number].place(x=100 + 40 + 10, y=15 + 40 + 5)760 elif take_coin_number == 1:761 remade_coin = self.make_canvas.create_oval(100+40+60+60, 15 + 40, 100+40+60+60+40, 15 + 40 + 40, width=3, fill="red", outline="black")762 self.red_number_label[take_coin_number].place(x=100 + 40 + 60 +60 + 10, y=15 + 40 + 5)763 elif take_coin_number == 2:764 remade_coin = self.make_canvas.create_oval(100 + 40 + 60 + 60, 15 + 40 + 100, 100 + 40 + 60 + 60 + 40, 15 + 40 + 40 + 100, width=3, fill="red", outline="black")765 self.red_number_label[take_coin_number].place(x=100 + 40 + 60 + 60 + 10, y=15 + 40 + 100 + 5)766 else:767 remade_coin = self.make_canvas.create_oval(100 + 40, 15 + 40+100, 100 + 40 + 40, 15 + 40 + 40+100, width=3,fill="red", outline="black")768 self.red_number_label[take_coin_number].place(x=100 + 40 + 10, y=15 + 40 + 100 + 5)769 self.made_red_coin[take_coin_number]=remade_coin770 if color_coin != "green":771 for take_coin_number in range(len(self.green_coord_store)):772 if self.green_coord_store[take_coin_number] == counter_coin:773 if path_to_traverse_before_overlap == 6:774 self.six_with_overlap = 1775 else:776 self.time_for-=1777 self.make_canvas.delete(self.made_green_coin[take_coin_number])778 self.green_number_label[take_coin_number].place_forget()779 self.green_coin_position[take_coin_number] = -1780 self.green_coord_store[take_coin_number] = -1781 if take_coin_number == 0:782 remade_coin = self.make_canvas.create_oval(340+(40*3)+40, 15 + 40, 340+(40*3)+40 + 40, 15 + 40 + 40, width=3, fill="#00FF00", outline="black")783 self.green_number_label[take_coin_number].place(x=340 + (40 * 3) + 40 + 10, y=15 + 40 + 5)784 elif take_coin_number == 1:785 remade_coin = self.make_canvas.create_oval(340+(40*3)+40+ 60 + 40+20, 15 + 40, 340+(40*3)+40 + 60 + 40 + 40+20, 15 + 40 + 40, width=3, fill="#00FF00", outline="black")786 self.green_number_label[take_coin_number].place(x=340 + (40 * 3) + 40 + 40 + 60 + 30, y=15 + 40 + 5)787 elif take_coin_number == 2:788 remade_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40 + 60 + 40 + 20, 15 + 40 + 100, 340 + (40 * 3) + 40 + 60 + 40 + 40 + 20, 15 + 40 + 40 + 100, width=3, fill="#00FF00", outline="black")789 self.green_number_label[take_coin_number].place(x=340 + (40 * 3) + 40 + 40 + 60 + 30, y=15 + 40 + 100 + 5)790 else:791 remade_coin = self.make_canvas.create_oval(340+(40*3)+40, 15 + 40 + 100, 340+(40*3)+40 + 40, 15 + 40 + 40 + 100, width=3, fill="#00FF00", outline="black")792 self.green_number_label[take_coin_number].place(x=340+(40*3) + 40 + 10, y=15 + 40 + 100 + 5)793 self.made_green_coin[take_coin_number] = remade_coin794 if color_coin != "yellow":795 for take_coin_number in range(len(self.yellow_coord_store)):796 if self.yellow_coord_store[take_coin_number] == counter_coin:797 if path_to_traverse_before_overlap == 6:798 self.six_with_overlap = 1799 else:800 self.time_for -= 1801 self.make_canvas.delete(self.made_yellow_coin[take_coin_number])802 self.yellow_number_label[take_coin_number].place_forget()803 self.yellow_coin_position[take_coin_number] = -1804 self.yellow_coord_store[take_coin_number] = -1805 if take_coin_number == 0:806 remade_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40, 340+80+15, 340 + (40 * 3) + 40 + 40, 340+80+40+15, width=3, fill="yellow", outline="black")807 self.yellow_number_label[take_coin_number].place(x=340+(40*3) + 40 + 10, y=30 + (40*6)+(40*3)+40+10)808 elif take_coin_number == 1:809 remade_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40 + 60 + 40 + 20, 340+80+15, 340 + (40 * 3) + 40 + 60 + 40 + 40+20, 340+80+40+15, width=3, fill="yellow", outline="black")810 self.yellow_number_label[take_coin_number].place(x=340+(40*3)+ 40 + 40+ 60 + 30, y=30 + (40*6)+(40*3)+40+10)811 elif take_coin_number == 2:812 remade_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40 + 60 + 40 + 20, 340 + 80 + 60 + 40 + 15, 340 + (40 * 3) + 40 + 60 + 40 + 40 + 20, 340 + 80 + 60 + 40 + 40 + 15, width=3, fill="yellow", outline="black")813 self.yellow_number_label[take_coin_number].place(x=340+(40*3)+ 40 + 40+ 60 + 30, y=30 + (40*6)+(40*3)+40+100+10)814 else:815 remade_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40, 340+80+60+40+15, 340 + (40 * 3) + 40 + 40,340+80+60+40+40+15, width=3, fill="yellow", outline="black")816 self.yellow_number_label[take_coin_number].place(x=340 + (40 * 3) + 40 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 100 + 10)817 self.made_yellow_coin[take_coin_number] = remade_coin818 if color_coin != "sky_blue":819 for take_coin_number in range(len(self.sky_blue_coord_store)):820 if self.sky_blue_coord_store[take_coin_number] == counter_coin:821 if path_to_traverse_before_overlap == 6:822 self.six_with_overlap = 1823 else:824 self.time_for -= 1825 self.make_canvas.delete(self.made_sky_blue_coin[take_coin_number])826 self.sky_blue_number_label[take_coin_number].place_forget()827 self.sky_blue_coin_position[take_coin_number] = -1828 self.sky_blue_coord_store[take_coin_number]=-1829 if take_coin_number == 0:830 remade_coin = self.make_canvas.create_oval(100 + 40, 340+80+15, 100 + 40 + 40, 340+80+40+15, width=3, fill="#04d9ff", outline="black")831 self.sky_blue_number_label[take_coin_number].place(x=100+40+10, y=30 + (40*6)+(40*3)+40+10)832 elif take_coin_number == 1:833 remade_coin = self.make_canvas.create_oval(100 + 40 + 60 + 40+20, 340+80+15, 100 + 40 + 60 + 40 + 40+20, 340+80+40+15, width=3, fill="#04d9ff", outline="black")834 self.sky_blue_number_label[take_coin_number].place(x=100 + 40 + 60 +60 + 10, y=30 + (40*6)+(40*3)+40+10)835 elif take_coin_number == 2:836 remade_coin = self.make_canvas.create_oval(100 + 40 + 60 + 40 + 20, 340 + 80 + 60 + 40 + 15, 100 + 40 + 60 + 40 + 40 + 20, 340 + 80 + 60 + 40 + 40 + 15, width=3, fill="#04d9ff", outline="black")837 self.sky_blue_number_label[take_coin_number].place(x=100 + 40 + 60 + 60 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 60 + 40 + 10)838 else:839 remade_coin = self.make_canvas.create_oval( 100 + 40, 340+80+60+40+15, 100 + 40 + 40, 340+80+60+40+40+15, width=3, fill="#04d9ff", outline="black")840 self.sky_blue_number_label[take_coin_number].place(x=100+40+10, y=30 + (40*6)+(40*3)+40+60+40+10)841 self.made_sky_blue_coin[take_coin_number] = remade_coin842 def under_room_traversal_control(self,specific_coin,number_label,number_label_x,number_label_y,path_counter,counter_coin,color_coin):843 if color_coin == "red" and counter_coin >= 100:844 if int(counter_coin)+int(path_counter)<=106:845 counter_coin = self.room_red_traversal(specific_coin, number_label, number_label_x, number_label_y, path_counter, counter_coin)846 elif color_coin == "green" and counter_coin >= 100:847 if int(counter_coin) + int(path_counter) <= 106:848 counter_coin = self.room_green_traversal(specific_coin, number_label, number_label_x, number_label_y,path_counter,counter_coin)849 elif color_coin == "yellow" and counter_coin >= 100:850 if int(counter_coin) + int(path_counter) <= 106:851 counter_coin = self.room_yellow_traversal(specific_coin, number_label, number_label_x, number_label_y,path_counter,counter_coin)852 elif color_coin == "sky_blue" and counter_coin >= 100:853 if int(counter_coin) + int(path_counter) <= 106:854 counter_coin = self.room_sky_blue_traversal(specific_coin, number_label, number_label_x, number_label_y,path_counter,counter_coin)855 return counter_coin856 def room_red_traversal(self, specific_coin, number_label, number_label_x, number_label_y, path_counter, counter_coin):857 while path_counter>0:858 counter_coin += 1859 path_counter -= 1860 self.make_canvas.move(specific_coin, 40, 0)861 number_label_x+=40862 number_label.place(x=number_label_x,y=number_label_y)863 self.window.update()864 time.sleep(0.2)865 return counter_coin866 def room_green_traversal(self, specific_coin, number_label, number_label_x, number_label_y, path_counter, counter_coin):867 while path_counter > 0:868 counter_coin += 1869 path_counter -= 1870 self.make_canvas.move(specific_coin, 0, 40)871 number_label_y += 40872 number_label.place(x=number_label_x, y=number_label_y)873 self.window.update()874 time.sleep(0.2)875 return counter_coin876 def room_yellow_traversal(self, specific_coin, number_label, number_label_x, number_label_y,path_counter,counter_coin):877 while path_counter > 0:878 counter_coin += 1879 path_counter -= 1880 self.make_canvas.move(specific_coin, -40, 0)881 number_label_x -= 40882 number_label.place(x=number_label_x, y=number_label_y)883 self.window.update()884 time.sleep(0.2)885 return counter_coin886 def room_sky_blue_traversal(self, specific_coin, number_label, number_label_x, number_label_y,path_counter,counter_coin):887 while path_counter > 0:888 counter_coin += 1889 path_counter -= 1890 self.make_canvas.move(specific_coin, 0, -40)891 number_label_y -= 40892 number_label.place(x=number_label_x, y=number_label_y)893 self.window.update()894 time.sleep(0.2)895 return counter_coin896 def check_winner_and_runner(self,color_coin):897 destination_reached = 0 # Check for all specific color coins898 if color_coin == "red":899 temp_store = self.red_coord_store900 temp_delete = 0# Player index901 elif color_coin == "green":902 temp_store = self.green_coord_store903 temp_delete = 3# Player index904 elif color_coin == "yellow":905 temp_store = self.yellow_coord_store906 temp_delete = 2# Player index907 else:908 temp_store = self.sky_blue_coord_store909 temp_delete = 1# Player index910 for take in temp_store:911 if take == 106:912 destination_reached = 1913 else:914 destination_reached = 0915 break916 if destination_reached == 1:# If all coins in block reach to the destination, winner and runner check917 self.take_permission += 1918 if self.take_permission == 1:# Winner check919 messagebox.showinfo("Winner","Congrats! You are the winner")920 elif self.take_permission == 2:# 1st runner check921 messagebox.showinfo("Winner", "Wow! You are 1st runner")922 elif self.take_permission == 3:# 2nd runner check923 messagebox.showinfo("Winner", "Wow! You are 2nd runner")924 self.block_value_predict[temp_delete][1]['state'] = DISABLED925 self.total_people_play.remove(temp_delete)926 if len(self.total_people_play) == 1:927 messagebox.showinfo("Game Over","Good bye!!!!")928 self.block_value_predict[0][1]['state'] = DISABLED929 return False930 else:931 self.time_for-=1932 else:933 print("Winner not decided")934 return True935 # Input value checking936 def input_filtering(self,coin_number):937 try:938 if (4>=int(coin_number)>=1) or type(coin_number) == int:939 return True940 else:941 return False942 except:943 return False944if __name__ == '__main__':945 window = Tk()946 window.geometry("800x630")947 window.maxsize(800,630)948 window.minsize(800,630)949 window.title("Play Ludo with Aditya")950 window.iconbitmap("Images/ludo_icon.ico")951 block_six_side = ImageTk.PhotoImage(Image.open("Images/6_block.png").resize((33, 33), Image.ANTIALIAS))952 block_five_side = ImageTk.PhotoImage(Image.open("Images/5_block.png").resize((33, 33), Image.ANTIALIAS))953 block_four_side = ImageTk.PhotoImage(Image.open("Images/4_block.png").resize((33, 33), Image.ANTIALIAS))954 block_three_side = ImageTk.PhotoImage(Image.open("Images/3_block.png").resize((33, 33), Image.ANTIALIAS))955 block_two_side = ImageTk.PhotoImage(Image.open("Images/2_block.png").resize((33, 33), Image.ANTIALIAS))956 block_one_side = ImageTk.PhotoImage(Image.open("Images/1_block.png").resize((33, 33), Image.ANTIALIAS))957 Ludo(window,block_six_side,block_five_side,block_four_side,block_three_side,block_two_side,block_one_side)...
ludo.py
Source:ludo.py
1 # Ludo game with Sam #2from tkinter import *3from tkinter import messagebox4from PIL import Image,ImageTk5import time6from random import randint7class Ludo:8 def __init__(self, root,six_side_block,five_side_block,four_side_block,three_side_block,two_side_block,one_side_block):9 self.window = root10 # Make canvas11 self.make_canvas = Canvas(self.window, bg="#4d4dff", width=800, height=630)12 self.make_canvas.pack(fill=BOTH,expand=1)13 # Make some containers to store data14 self.made_red_coin = []15 self.made_green_coin = []16 self.made_yellow_coin = []17 self.made_sky_blue_coin = []18 self.red_number_label = []19 self.green_number_label = []20 self.yellow_number_label = []21 self.sky_blue_number_label = []22 self.block_value_predict = []23 self.total_people_play = []24 # Ludo block all side image store25 self.block_number_side = [one_side_block, two_side_block, three_side_block, four_side_block, five_side_block, six_side_block]26 # Use for store specific position of all coins27 self.red_coord_store = [-1, -1, -1, -1]28 self.green_coord_store = [-1, -1, -1, -1]29 self.yellow_coord_store = [-1, -1, -1, -1]30 self.sky_blue_coord_store = [-1, -1, -1, -1]31 self.red_coin_position = [0, 1, 2, 3]32 self.green_coin_position = [0, 1, 2, 3]33 self.yellow_coin_position = [0, 1, 2, 3]34 self.sky_blue_coin_position = [0, 1, 2, 3]35 for index in range(len(self.red_coin_position)):# Specific coin position set to -1 by default36 self.red_coin_position[index] = -137 self.green_coin_position[index] = -138 self.yellow_coin_position[index] = -139 self.sky_blue_coin_position[index] = -140 # Number to room to be traverse by specific color coin, store in that variable41 self.move_red_counter = 042 self.move_green_counter = 043 self.move_yellow_counter = 044 self.move_sky_blue_counter = 045 self.take_permission = 046 self.six_with_overlap = 047 self.red_store_active = 048 self.sky_blue_store_active = 049 self.yellow_store_active = 050 self.green_store_active = 051 self.six_counter = 052 self.time_for = -153 # Some variables initializes with None54 self.right_star = None55 self.down_star = None56 self.left_star = None57 self.up_star = None58 # By default some function call59 self.board_set_up()60 self.instruction_btn_red()61 self.instruction_btn_sky_blue()62 self.instruction_btn_yellow()63 self.instruction_btn_green()64 self.take_initial_control()65 def board_set_up(self):66 # Cover Box made67 self.make_canvas.create_rectangle(100, 15, 100 + (40 * 15), 15 + (40 * 15), width=6, fill="white")68 # Square box69 self.make_canvas.create_rectangle(100, 15, 100+240, 15+240, width=3, fill="red")# left up large square70 self.make_canvas.create_rectangle(100, (15+240)+(40*3), 100+240, (15+240)+(40*3)+(40*6), width=3, fill="#04d9ff")# left down large square71 self.make_canvas.create_rectangle(340+(40*3), 15, 340+(40*3)+(40*6), 15+240, width=3, fill="#00FF00")# right up large square72 self.make_canvas.create_rectangle(340+(40*3), (15+240)+(40*3), 340+(40*3)+(40*6), (15+240)+(40*3)+(40*6), width=3, fill="yellow")# right down large square73 # Left 3 box(In white region)74 self.make_canvas.create_rectangle(100, (15+240), 100+240, (15+240)+40, width=3)75 self.make_canvas.create_rectangle(100+40, (15 + 240)+40, 100 + 240, (15 + 240) + 40+40, width=3, fill="#F00000")76 self.make_canvas.create_rectangle(100, (15 + 240)+80, 100 + 240, (15 + 240) + 80+40, width=3)77 # right 3 box(In white region)78 self.make_canvas.create_rectangle(100+240, 15, 100 + 240+40, 15 + (40*6), width=3)79 self.make_canvas.create_rectangle(100+240+40, 15+40, 100+240+80, 15 + (40*6), width=3, fill="#00FF00")80 self.make_canvas.create_rectangle(100+240+80, 15, 100 + 240+80+40, 15 + (40*6), width=3)81 # up 3 box(In white region)82 self.make_canvas.create_rectangle(340+(40*3), 15+240, 340+(40*3)+(40*6), 15+240+40, width=3)83 self.make_canvas.create_rectangle(340+(40*3), 15+240+40, 340+(40*3)+(40*6)-40, 15+240+80, width=3, fill="yellow")84 self.make_canvas.create_rectangle(340+(40*3), 15+240+80, 340+(40*3)+(40*6), 15+240+120, width=3)85 # down 3 box(In white region)86 self.make_canvas.create_rectangle(100, (15 + 240)+(40*3), 100 + 240+40, (15 + 240)+(40*3)+(40*6), width=3)87 self.make_canvas.create_rectangle(100+240+40, (15 + 240)+(40*3), 100 + 240+40+40, (15 + 240)+(40*3)+(40*6)-40, width=3, fill="#04d9ff")88 self.make_canvas.create_rectangle(100 + 240+40+40, (15 + 240)+(40*3), 100 + 240+40+40+40, (15 + 240)+(40*3)+(40*6), width=3)89 # All left separation line90 start_x = 100 + 4091 start_y = 15 + 24092 end_x = 100 + 4093 end_y = 15 + 240 + (40 * 3)94 for _ in range(5):95 self.make_canvas.create_line(start_x, start_y, end_x, end_y, width=3)96 start_x+=4097 end_x+= 4098 # All right separation line99 start_x = 100+240+(40*3)+40100 start_y = 15 + 240101 end_x = 100+240+(40*3)+40102 end_y = 15 + 240 + (40 * 3)103 for _ in range(5):104 self.make_canvas.create_line(start_x, start_y, end_x, end_y, width=3)105 start_x += 40106 end_x += 40107 # All up separation done108 start_x = 100+240109 start_y = 15+40110 end_x = 100+240+(40*3)111 end_y = 15+40112 for _ in range(5):113 self.make_canvas.create_line(start_x, start_y, end_x, end_y, width=3)114 start_y += 40115 end_y += 40116 # All down separation done117 start_x = 100 + 240118 start_y = 15 + (40*6)+(40*3)+40119 end_x = 100 + 240 + (40 * 3)120 end_y = 15 + (40*6)+(40*3)+40121 for _ in range(5):122 self.make_canvas.create_line(start_x, start_y, end_x, end_y, width=3)123 start_y += 40124 end_y += 40125 # Square box(Coins containers) white region make126 self.make_canvas.create_rectangle(100+20, 15+40-20, 100 + 40 + 60 + 40 +60+20, 15+40+40+40+100-20, width=3, fill="white")127 self.make_canvas.create_rectangle(340+(40*3)+40 - 20, 15 + 40-20, 340+(40*3)+40 + 60 + 40 + 40+20+20, 15+40+40+40+100-20, width=3, fill="white")128 self.make_canvas.create_rectangle(100+20, 340+80-20+15, 100 + 40 + 60 + 40 +60+20, 340+80+60+40+40+20+15, width=3, fill="white")129 self.make_canvas.create_rectangle(340+(40*3)+40 - 20, 340 + 80 - 20+15, 340+(40*3)+40 + 60 + 40 + 40+20+20, 340 + 80 + 60 + 40 + 40 + 20+15, width=3, fill="white")130 # Left up square inside box made131 self.make_canvas.create_rectangle(100+40, 15+40, 100+40+40, 15+40+40, width=3, fill="red")132 self.make_canvas.create_rectangle(100+40+60+60, 15 + 40, 100+40+60+40+60, 15 + 40 + 40, width=3, fill="red")133 self.make_canvas.create_rectangle(100 + 40, 15 + 40+100, 100 + 40 + 40, 15 + 40 + 40+100, width=3, fill="red")134 self.make_canvas.create_rectangle(100 + 40 + 60 + 60, 15 + 40+100, 100 + 40 + 60 + 40 +60, 15 + 40 + 40+100, width=3, fill="red")135 # Right up square inside box made136 self.make_canvas.create_rectangle(340+(40*3)+40, 15 + 40, 340+(40*3)+40 + 40, 15 + 40 + 40, width=3, fill="#00FF00")137 self.make_canvas.create_rectangle(340+(40*3)+40+ 60 + 40+20, 15 + 40, 340+(40*3)+40 + 60 + 40 + 40+20, 15 + 40 + 40, width=3, fill="#00FF00")138 self.make_canvas.create_rectangle(340+(40*3)+40, 15 + 40 + 100, 340+(40*3)+40 + 40, 15 + 40 + 40 + 100, width=3, fill="#00FF00")139 self.make_canvas.create_rectangle(340+(40*3)+40+ 60 + 40+20, 15 + 40 + 100, 340+(40*3)+40 + 60 + 40 + 40+20, 15 + 40 + 40 + 100, width=3, fill="#00FF00")140 # Left down square inside box made141 self.make_canvas.create_rectangle(100 + 40, 340+80+15, 100 + 40 + 40, 340+80+40+15, width=3, fill="#04d9ff")142 self.make_canvas.create_rectangle(100 + 40 + 60 + 40+20, 340+80+15, 100 + 40 + 60 + 40 + 40+20, 340+80+40+15, width=3, fill="#04d9ff")143 self.make_canvas.create_rectangle(100 + 40, 340+80+60+40+15, 100 + 40 + 40, 340+80+60+40+40+15, width=3, fill="#04d9ff")144 self.make_canvas.create_rectangle(100 + 40 + 60 + 40+20, 340+80+60+40+15, 100 + 40 + 60 + 40 + 40+20, 340+80+60+40+40+15, width=3, fill="#04d9ff")145 # Right down square inside box made146 self.make_canvas.create_rectangle(340 + (40 * 3) + 40, 340+80+15, 340 + (40 * 3) + 40 + 40, 340+80+40+15, width=3, fill="yellow")147 self.make_canvas.create_rectangle(340 + (40 * 3) + 40 + 60 + 40+20, 340+80+15, 340 + (40 * 3) + 40 + 60 + 40 + 40+20, 340+80+40+15, width=3, fill="yellow")148 self.make_canvas.create_rectangle(340 + (40 * 3) + 40, 340+80+60+40+15, 340 + (40 * 3) + 40 + 40,340+80+60+40+40+15, width=3, fill="yellow")149 self.make_canvas.create_rectangle(340 + (40 * 3) + 40 + 60 + 40+20, 340+80+60+40+15,340 + (40 * 3) + 40 + 60 + 40 + 40+20, 340+80+60+40+40+15, width=3, fill="yellow")150 # sky_blue start position151 self.make_canvas.create_rectangle(100+240,340+(40*5)-5,100+240+40,340+(40*6)-5,fill="#04d9ff",width=3)152 # Red start position153 self.make_canvas.create_rectangle(100 + 40, 15+(40*6), 100 +40 + 40, 15+(40*6)+40, fill="red", width=3)154 # Green start position155 self.make_canvas.create_rectangle(100 + (40*8), 15 + 40, 100 +(40*9), 15 + 40+ 40, fill="#00FF00", width=3)156 # Yellow start position157 self.make_canvas.create_rectangle(100 + (40 * 6)+(40*3)+(40*4), 15 + (40*8), 100 + (40 * 6)+(40*3)+(40*5), 15 + (40*9), fill="yellow", width=3)158 # Traingle in middle159 self.make_canvas.create_polygon(100+240, 15+240, 100+240+60, 15+240+60, 100+240, 15+240+(40*3), width=3,fill="red",outline="black")160 self.make_canvas.create_polygon(100 + 240+(40*3), 15 + 240, 100 + 240 + 60, 15 + 240 + 60, 100 + 240+(40*3), 15 + 240 + (40 * 3), width=3, fill="yellow",outline="black")161 self.make_canvas.create_polygon(100 + 240, 15 + 240, 100 + 240 + 60, 15 + 240 + 60, 100 + 240 + (40 * 3), 15 + 240, width=3, fill="#00FF00",outline="black")162 self.make_canvas.create_polygon(100 + 240, 15 + 240+(40*3), 100 + 240 + 60, 15 + 240 + 60, 100 + 240 + (40 * 3), 15 + 240+(40*3), width=3, fill="#04d9ff",outline="black")163 # Make coin for red left up block164 red_1_coin = self.make_canvas.create_oval(100+40, 15+40, 100+40+40, 15+40+40, width=3, fill="red", outline="black")165 red_2_coin = self.make_canvas.create_oval(100+40+60+60, 15 + 40, 100+40+60+60+40, 15 + 40 + 40, width=3, fill="red", outline="black")166 red_3_coin = self.make_canvas.create_oval(100 + 40 + 60 + 60, 15 + 40 + 100, 100 + 40 + 60 + 60 + 40, 15 + 40 + 40 + 100, width=3, fill="red", outline="black")167 red_4_coin = self.make_canvas.create_oval(100 + 40, 15 + 40+100, 100 + 40 + 40, 15 + 40 + 40+100, width=3,fill="red", outline="black")168 self.made_red_coin.append(red_1_coin)169 self.made_red_coin.append(red_2_coin)170 self.made_red_coin.append(red_3_coin)171 self.made_red_coin.append(red_4_coin)172 # Make coin under number label for red left up block173 red_1_label = Label(self.make_canvas, text="1", font=("Arial", 15, "bold"), bg="red", fg="black")174 red_1_label.place(x=100 + 40 + 10, y=15 + 40 + 5)175 red_2_label = Label(self.make_canvas, text="2", font=("Arial", 15, "bold"), bg="red", fg="black")176 red_2_label.place(x=100 + 40 + 60 + 60 + 10, y=15 + 40 + 5)177 red_3_label = Label(self.make_canvas, text="3", font=("Arial", 15, "bold"), bg="red", fg="black")178 red_3_label.place(x=100 + 40 + 60 + 60 + 10, y=15 + 40 + 100 + 5)179 red_4_label = Label(self.make_canvas, text="4", font=("Arial", 15, "bold"), bg="red", fg="black")180 red_4_label.place(x=100 + 40 + 10, y=15 + 40 + 100 + 5)181 self.red_number_label.append(red_1_label)182 self.red_number_label.append(red_2_label)183 self.red_number_label.append(red_3_label)184 self.red_number_label.append(red_4_label)185 # Make coin for green right up block186 green_1_coin = self.make_canvas.create_oval(340+(40*3)+40, 15 + 40, 340+(40*3)+40 + 40, 15 + 40 + 40, width=3, fill="#00FF00", outline="black")187 green_2_coin = self.make_canvas.create_oval(340+(40*3)+40+ 60 + 40+20, 15 + 40, 340+(40*3)+40 + 60 + 40 + 40+20, 15 + 40 + 40, width=3, fill="#00FF00", outline="black")188 green_3_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40 + 60 + 40 + 20, 15 + 40 + 100, 340 + (40 * 3) + 40 + 60 + 40 + 40 + 20, 15 + 40 + 40 + 100, width=3, fill="#00FF00", outline="black")189 green_4_coin = self.make_canvas.create_oval(340+(40*3)+40, 15 + 40 + 100, 340+(40*3)+40 + 40, 15 + 40 + 40 + 100, width=3, fill="#00FF00", outline="black")190 self.made_green_coin.append(green_1_coin)191 self.made_green_coin.append(green_2_coin)192 self.made_green_coin.append(green_3_coin)193 self.made_green_coin.append(green_4_coin)194 # Make coin under number label for green right up block195 green_1_label = Label(self.make_canvas, text="1", font=("Arial", 15, "bold"), bg="#00FF00", fg="black")196 green_1_label.place(x=340 + (40 * 3) + 40 + 10, y=15 + 40 + 5)197 green_2_label = Label(self.make_canvas, text="2", font=("Arial", 15, "bold"), bg="#00FF00", fg="black")198 green_2_label.place(x=340 + (40 * 3) + 40 + 40 + 60 + 30, y=15 + 40 + 5)199 green_3_label = Label(self.make_canvas, text="3", font=("Arial", 15, "bold"), bg="#00FF00", fg="black")200 green_3_label.place(x=340 + (40 * 3) + 40 + 40 + 60 + 30, y=15 + 40 + 100 + 5)201 green_4_label = Label(self.make_canvas, text="4", font=("Arial", 15, "bold"), bg="#00FF00", fg="black")202 green_4_label.place(x=340 + (40 * 3) + 40 + 10, y=15 + 40 + 100 + 5)203 self.green_number_label.append(green_1_label)204 self.green_number_label.append(green_2_label)205 self.green_number_label.append(green_3_label)206 self.green_number_label.append(green_4_label)207 # Make coin for sky_blue left down block208 sky_blue_1_coin = self.make_canvas.create_oval(100 + 40, 340+80+15, 100 + 40 + 40, 340+80+40+15, width=3, fill="#04d9ff", outline="black")209 sky_blue_2_coin = self.make_canvas.create_oval(100 + 40 + 60 + 40+20, 340+80+15, 100 + 40 + 60 + 40 + 40+20, 340+80+40+15, width=3, fill="#04d9ff", outline="black")210 sky_blue_3_coin = self.make_canvas.create_oval(100 + 40 + 60 + 40 + 20, 340 + 80 + 60 + 40 + 15, 100 + 40 + 60 + 40 + 40 + 20, 340 + 80 + 60 + 40 + 40 + 15, width=3, fill="#04d9ff", outline="black")211 sky_blue_4_coin = self.make_canvas.create_oval( 100 + 40, 340+80+60+40+15, 100 + 40 + 40, 340+80+60+40+40+15, width=3, fill="#04d9ff", outline="black")212 self.made_sky_blue_coin.append(sky_blue_1_coin)213 self.made_sky_blue_coin.append(sky_blue_2_coin)214 self.made_sky_blue_coin.append(sky_blue_3_coin)215 self.made_sky_blue_coin.append(sky_blue_4_coin)216 # Make coin under number label for sky_blue left down block217 sky_blue_1_label = Label(self.make_canvas, text="1", font=("Arial", 15, "bold"), bg="#04d9ff", fg="black")218 sky_blue_1_label.place(x=100 + 40 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 10)219 sky_blue_2_label = Label(self.make_canvas, text="2", font=("Arial", 15, "bold"), bg="#04d9ff", fg="black")220 sky_blue_2_label.place(x=100 + 40 + 60 + 60 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 10)221 sky_blue_3_label = Label(self.make_canvas, text="3", font=("Arial", 15, "bold"), bg="#04d9ff", fg="black")222 sky_blue_3_label.place(x=100 + 40 + 60 + 60 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 60 + 40 + 10)223 sky_blue_4_label = Label(self.make_canvas, text="4", font=("Arial", 15, "bold"), bg="#04d9ff", fg="black")224 sky_blue_4_label.place(x=100 + 40 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 60 + 40 + 10)225 self.sky_blue_number_label.append(sky_blue_1_label)226 self.sky_blue_number_label.append(sky_blue_2_label)227 self.sky_blue_number_label.append(sky_blue_3_label)228 self.sky_blue_number_label.append(sky_blue_4_label)229 # Make coin for yellow right down block230 yellow_1_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40, 340+80+15, 340 + (40 * 3) + 40 + 40, 340+80+40+15, width=3, fill="yellow", outline="black")231 yellow_2_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40 + 60 + 40 + 20, 340+80+15, 340 + (40 * 3) + 40 + 60 + 40 + 40+20, 340+80+40+15, width=3, fill="yellow", outline="black")232 yellow_3_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40 + 60 + 40 + 20, 340 + 80 + 60 + 40 + 15, 340 + (40 * 3) + 40 + 60 + 40 + 40 + 20, 340 + 80 + 60 + 40 + 40 + 15, width=3, fill="yellow", outline="black")233 yellow_4_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40, 340+80+60+40+15, 340 + (40 * 3) + 40 + 40,340+80+60+40+40+15, width=3, fill="yellow", outline="black")234 self.made_yellow_coin.append(yellow_1_coin)235 self.made_yellow_coin.append(yellow_2_coin)236 self.made_yellow_coin.append(yellow_3_coin)237 self.made_yellow_coin.append(yellow_4_coin)238 # Make coin under number label for yellow right down block239 yellow_1_label = Label(self.make_canvas, text="1", font=("Arial", 15, "bold"), bg="yellow", fg="black")240 yellow_1_label.place(x=340 + (40 * 3) + 40 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 10)241 yellow_2_label = Label(self.make_canvas, text="2", font=("Arial", 15, "bold"), bg="yellow", fg="black")242 yellow_2_label.place(x=340 + (40 * 3) + 40 + 40 + 60 + 30, y=30 + (40 * 6) + (40 * 3) + 40 + 10)243 yellow_3_label = Label(self.make_canvas, text="3", font=("Arial", 15, "bold"), bg="yellow", fg="black")244 yellow_3_label.place(x=340 + (40 * 3) + 40 + 40 + 60 + 30, y=30 + (40 * 6) + (40 * 3) + 40 + 100 + 10)245 yellow_4_label = Label(self.make_canvas, text="4", font=("Arial", 15, "bold"), bg="yellow", fg="black")246 yellow_4_label.place(x=340 + (40 * 3) + 40 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 100 + 10)247 self.yellow_number_label.append(yellow_1_label)248 self.yellow_number_label.append(yellow_2_label)249 self.yellow_number_label.append(yellow_3_label)250 self.yellow_number_label.append(yellow_4_label)251 # Make star safe zone252 """253 A254 L * B255 K * * * * * * C256 * *257 J * * D258 * *259 I* * * * * * E260 H * F261 G262 """263 # Right star264 common_x = 340+(40*6)+20265 common_y = 15+240+2266 # A B C D E F G H I J K L267 coord = [common_x,common_y, common_x+5,common_y+15, common_x+15,common_y+15, common_x+8,common_y+20, common_x+15,common_y+25, common_x+5,common_y+25, common_x,common_y+25+10, common_x-5,common_y+25, common_x-16,common_y+25, common_x-8,common_y+15+5, common_x-15,common_y+15, common_x-5,common_y+15]268 self.make_canvas.create_polygon(coord,width=3,fill="blue")269 # Up star270 common_x = 100+240+2+18271 common_y = 15 + (40*2) + 2272 # A B C D E F G H I J K L273 coord = [common_x, common_y, common_x + 5, common_y + 15, common_x + 15, common_y + 15, common_x + 8, common_y + 20, common_x + 15, common_y + 25, common_x + 5, common_y + 25, common_x, common_y + 25 + 10, common_x - 5, common_y + 25, common_x - 16, common_y + 25, common_x - 8,common_y + 15 + 5, common_x - 15,common_y + 15, common_x - 5,common_y + 15]274 self.make_canvas.create_polygon(coord, width=3, fill="blue")275 # Left star276 common_x = 100 + (40*2) + 2 +18277 common_y = 15 + 240+(40*2) + 2278 # A B C D E F G H I J K L279 coord = [common_x, common_y, common_x + 5, common_y + 15, common_x + 15, common_y + 15, common_x + 8,common_y + 20, common_x + 15, common_y + 25, common_x + 5, common_y + 25, common_x, common_y + 25 + 10, common_x - 5, common_y + 25, common_x - 16, common_y + 25, common_x - 8, common_y + 15 + 5, common_x - 15, common_y + 15, common_x - 5, common_y + 15]280 self.make_canvas.create_polygon(coord, width=3, fill="blue")281 # Down star282 common_x = 100 + 240 + (40*2) + 2 + 18283 common_y = 15 + (40 * 6) + (40*3)+(40*3)+2284 # A B C D E F G H I J K L285 coord = [common_x, common_y, common_x + 5, common_y + 15, common_x + 15, common_y + 15, common_x + 8, common_y + 20, common_x + 15, common_y + 25, common_x + 5, common_y + 25, common_x, common_y + 25 + 10, common_x - 5, common_y + 25, common_x - 16, common_y + 25, common_x - 8, common_y + 15 + 5, common_x - 15, common_y + 15, common_x - 5, common_y + 15]286 self.make_canvas.create_polygon(coord, width=3, fill="blue")287 # Total number of players: Control take at first288 def take_initial_control(self):289 for i in range(4):290 self.block_value_predict[i][1]['state'] = DISABLED291 # Make other window to control take292 top = Toplevel()293 top.geometry("600x150")294 top.maxsize(600,150)295 top.minsize(600,150)296 top.config(bg="orange")297 top.iconbitmap("Images/ludo_icon.ico")298 head = Label(top,text="-:Total number of players:- ",font=("Arial",25,"bold","italic"),bg="orange",fg="chocolate")299 head.place(x=70,y=30)300 take_entry = Entry(top,font=("Arial",18,"bold","italic"),relief=SUNKEN,bd=7,width=12)301 take_entry.place(x=150,y=80)302 take_entry.focus()303 def filtering():# Total player input value filtering304 response_take = self.input_filtering(take_entry.get())305 if response_take is True and int(take_entry.get())>1:306 for player_index in range(int(take_entry.get())):307 self.total_people_play.append(player_index)308 print(self.total_people_play)309 self.make_command()310 top.destroy()311 else:312 messagebox.showerror("Input Error", "Please input number of players between 2 and 4")313 submit_btn = Button(top,text="Submit",bg="black",fg="#00FF00",font=("Arial",13,"bold"),relief=RAISED,bd=8,command=filtering)314 submit_btn.place(x=350,y=80)315 top.mainloop()316 # Get block value after prediction based on probability317 def make_prediction(self,color_indicator):318 try:319 if color_indicator == "red":320 block_value_predict = self.block_value_predict[0]321 permanent_block_number = self.move_red_counter = randint(1, 6)322 elif color_indicator == "sky_blue":323 block_value_predict = self.block_value_predict[1]324 permanent_block_number = self.move_sky_blue_counter = randint(1, 6)325 elif color_indicator == "yellow":326 block_value_predict = self.block_value_predict[2]327 permanent_block_number = self.move_yellow_counter = randint(1, 6)328 else:329 block_value_predict = self.block_value_predict[3]330 permanent_block_number = self.move_green_counter = randint(1, 6)331 block_value_predict[1]['state'] = DISABLED332 # Illusion of coin floating333 temp_counter = 15334 while temp_counter>0:335 move_temp_counter = randint(1, 6)336 block_value_predict[0]['image'] = self.block_number_side[move_temp_counter - 1]337 self.window.update()338 time.sleep(0.1)339 temp_counter-=1340 print("Prediction result: ", permanent_block_number)341 # Permanent predicted value containing image set342 block_value_predict[0]['image'] = self.block_number_side[permanent_block_number-1]343 self.instructional_btn_customization_based_on_current_situation(color_indicator,permanent_block_number,block_value_predict)344 except:345 print("Force stop error")346 def instructional_btn_customization_based_on_current_situation(self,color_indicator,permanent_block_number,block_value_predict):347 if color_indicator == "red":348 temp_coin_position = self.red_coin_position349 elif color_indicator == "green":350 temp_coin_position = self.green_coin_position351 elif color_indicator == "yellow":352 temp_coin_position = self.yellow_coin_position353 else:354 temp_coin_position = self.sky_blue_coin_position355 all_in = 1356 for i in range(4):357 if temp_coin_position[i] == -1:358 all_in = 1359 else:360 all_in = 0361 break362 if permanent_block_number == 6:363 self.six_counter += 1364 else:365 self.six_counter = 0366 if ((all_in == 1 and permanent_block_number == 6) or (all_in==0)) and self.six_counter<3:367 permission = 1368 if color_indicator == "red":369 temp = self.red_coord_store370 elif color_indicator == "green":371 temp = self.green_coord_store372 elif color_indicator == "yellow":373 temp = self.yellow_coord_store374 else:375 temp = self.sky_blue_coord_store376 if permanent_block_number<6:377 if self.six_with_overlap == 1:378 self.time_for-=1379 self.six_with_overlap=0380 for i in range(4):381 if temp[i] == -1:382 permission=0383 elif temp[i]>100:384 if temp[i]+permanent_block_number<=106:385 permission=1386 break387 else:388 permission=0389 else:390 permission=1391 break392 else:393 for i in range(4):394 if temp[i]>100:395 if temp[i] + permanent_block_number <= 106:396 permission = 1397 break398 else:399 permission = 0400 else:401 permission = 1402 break403 if permission == 0:404 self.make_command()405 else:406 block_value_predict[3]['state'] = NORMAL# Give btn activation407 block_value_predict[1]['state'] = DISABLED# Predict btn deactivation408 else:409 block_value_predict[1]['state'] = NORMAL# Predict btn activation410 if self.six_with_overlap == 1:411 self.time_for -= 1412 self.six_with_overlap = 0413 self.make_command()414 if permanent_block_number == 6 and self.six_counter<3 and block_value_predict[3]['state'] == NORMAL:415 self.time_for-=1416 else:417 self.six_counter=0418 # Player Scope controller419 def make_command(self):420 if self.time_for == -1:421 pass422 else:423 self.block_value_predict[self.total_people_play[self.time_for]][1]['state'] = DISABLED424 if self.time_for == len(self.total_people_play)-1:425 self.time_for = -1426 self.time_for+=1427 self.block_value_predict[self.total_people_play[self.time_for]][1]['state'] = NORMAL428 def instruction_btn_red(self):429 block_predict_red = Label(self.make_canvas,image=self.block_number_side[0])430 block_predict_red.place(x=45,y=15)431 predict_red = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Predict", font=("Arial", 8, "bold"), command=lambda: self.make_prediction("red"))432 predict_red.place(x=37, y=15 + 40)433 entry_take_red = Entry(self.make_canvas,bg="white",fg="blue",font=("Arial",25,"bold","italic"),width=2,relief=SUNKEN,bd=5)434 entry_take_red.place(x=40,y=15+80)435 final_move = Button(self.make_canvas,bg="black",fg="#00FF00",relief=RAISED,bd=5,text="Give",font=("Arial",8,"bold"),command=lambda: self.main_controller("red",entry_take_red.get()),state=DISABLED)436 final_move.place(x=42,y=15+140)437 Label(self.make_canvas,text="Player 1",bg="#4d4dff",fg="gold",font=("Arial",15,"bold")).place(x=15,y=15+140+40)438 self.store_instructional_btn(block_predict_red,predict_red,entry_take_red,final_move)439 def instruction_btn_sky_blue(self):440 block_predict_sky_blue = Label(self.make_canvas, image=self.block_number_side[0])441 block_predict_sky_blue.place(x=45, y=15+(40*6+40*3)+10)442 predict_sky_blue = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Predict",font=("Arial", 8, "bold"), command=lambda: self.make_prediction("sky_blue"))443 predict_sky_blue.place(x=37, y=15+(40*6+40*3)+40 + 10)444 entry_take_sky_blue = Entry(self.make_canvas, bg="white", fg="blue", font=("Arial", 25, "bold", "italic"), width=2,relief=SUNKEN, bd=5)445 entry_take_sky_blue.place(x=40, y=15+(40*6+40*3)+40 + 50)446 final_move = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Give", font=("Arial", 8, "bold"),command=lambda: self.main_controller("sky_blue",entry_take_sky_blue.get()),state=DISABLED)447 final_move.place(x=42, y=15+(40*6+40*3)+40 + 110)448 Label(self.make_canvas, text="Player 2", bg="#4d4dff", fg="gold", font=("Arial", 15, "bold")).place(x=15,y=15+(40*6+40*3)+40 + 110+ 40)449 self.store_instructional_btn(block_predict_sky_blue, predict_sky_blue, entry_take_sky_blue, final_move)450 def instruction_btn_yellow(self):451 block_predict_yellow = Label(self.make_canvas, image=self.block_number_side[0])452 block_predict_yellow.place(x=100 + (40 * 6 + 40 * 3 + 40 * 6 + 10)+10, y=15 + (40 * 6 + 40 * 3) + 10)453 predict_yellow = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Predict",font=("Arial", 8, "bold"), command=lambda: self.make_prediction("yellow"))454 predict_yellow.place(x=100 + (40 * 6 + 40 * 3 + 40 * 6 + 2)+10, y=15 + (40 * 6 + 40 * 3) + 40 + 10)455 entry_take_yellow = Entry(self.make_canvas, bg="white", fg="blue", font=("Arial", 25, "bold", "italic"),width=2, relief=SUNKEN, bd=5)456 entry_take_yellow.place(x=100 + (40 * 6 + 40 * 3 + 40 * 6 + 2)+13, y=15 + (40 * 6 + 40 * 3) + 40 + 50)457 final_move = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Give",font=("Arial", 8, "bold"),command=lambda: self.main_controller("yellow",entry_take_yellow.get()),state=DISABLED)458 final_move.place(x=100 + (40 * 6 + 40 * 3 + 40 * 6 + 2)+17, y=15 + (40 * 6 + 40 * 3) + 40 + 110)459 Label(self.make_canvas, text="Player 3", bg="#4d4dff", fg="gold", font=("Arial", 15, "bold")).place(x=100 + (40 * 6 + 40 * 3 + 40 * 6 + 3),y=15 + (40 * 6 + 40 * 3) + 40 + 110 + 40)460 self.store_instructional_btn(block_predict_yellow, predict_yellow, entry_take_yellow, final_move)461 def instruction_btn_green(self):462 block_predict_green = Label(self.make_canvas, image=self.block_number_side[0])463 block_predict_green.place(x=100+(40*6+40*3+40*6+10)+10, y=15)464 predict_green = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Predict", font=("Arial", 8, "bold"), command=lambda: self.make_prediction("green"))465 predict_green.place(x=100+(40*6+40*3+40*6+2)+10, y=15 + 40)466 entry_take_green = Entry(self.make_canvas, bg="white", fg="blue", font=("Arial", 25, "bold", "italic"), width=2, relief=SUNKEN, bd=5)467 entry_take_green.place(x=100+(40*6+40*3+40*6+2)+13, y=15 + 80)468 final_move = Button(self.make_canvas, bg="black", fg="#00FF00", relief=RAISED, bd=5, text="Give",font=("Arial", 8, "bold"),command=lambda: self.main_controller("green",entry_take_green.get()),state=DISABLED)469 final_move.place(x=100+(40*6+40*3+40*6+2)+17, y=15 + 140)470 Label(self.make_canvas, text="Player 4", bg="#4d4dff", fg="gold", font=("Arial", 15, "bold")).place(x=100+(40*6+40*3+40*6+3), y=15 + 140+40)471 self.store_instructional_btn(block_predict_green, predict_green, entry_take_green, final_move)472 def store_instructional_btn(self, block_indicator, predictor, entry_controller, give_finally):473 temp = []474 temp.append(block_indicator)475 temp.append(predictor)476 temp.append(entry_controller)477 temp.append(give_finally)478 self.block_value_predict.append(temp)479 # self.block_value_predict[0] = red instruction information480 # self.block_value_predict[1] = sky_blue instruction information481 # self.block_value_predict[2] = yellow instruction information482 # self.block_value_predict[3] = green instruction information483 # self.block_value_predict[something][1] = Predict btn484 # self.block_value_predict[something][3] = Give btn485 def red_circle_start_position(self, coin_number):486 self.make_canvas.delete(self.made_red_coin[int(coin_number)-1])487 self.made_red_coin[int(coin_number)-1] = self.make_canvas.create_oval(100 + 40, 15+(40*6), 100 +40 + 40, 15+(40*6)+40, fill="red", width=3, outline="black")488 self.red_number_label[int(coin_number)-1].place_forget()489 red_start_label_x = 100 + 40 + 10490 red_start_label_y = 15 + (40 * 6) + 5491 self.red_number_label[int(coin_number)-1].place(x=red_start_label_x, y=red_start_label_y)492 self.red_coin_position[int(coin_number)-1] = 1493 self.window.update()494 time.sleep(0.2)495 def green_circle_start_position(self,coin_number):496 self.make_canvas.delete(self.made_green_coin[int(coin_number)-1])497 self.made_green_coin[int(coin_number)-1] = self.make_canvas.create_oval(100 + (40*8), 15 + 40, 100 +(40*9), 15 + 40+ 40, fill="#00FF00", width=3)498 self.green_number_label[int(coin_number)-1].place_forget()499 green_start_label_x = 100 + (40*8) + 10500 green_start_label_y = 15 + 40 + 5501 self.green_number_label[int(coin_number)-1].place(x=green_start_label_x, y=green_start_label_y)502 self.green_coin_position[int(coin_number)-1] = 14503 self.window.update()504 time.sleep(0.2)505 def yellow_circle_start_position(self,coin_number):506 self.make_canvas.delete(self.made_yellow_coin[int(coin_number)-1])507 self.made_yellow_coin[int(coin_number)-1] = self.make_canvas.create_oval(100 + (40 * 6)+(40*3)+(40*4), 15 + (40*8), 100 + (40 * 6)+(40*3)+(40*5), 15 + (40*9), fill="yellow", width=3)508 self.yellow_number_label[int(coin_number)-1].place_forget()509 yellow_start_label_x = 100 + (40 * 6)+(40*3)+(40*4) + 10510 yellow_start_label_y = 15 + (40*8) + 5511 self.yellow_number_label[int(coin_number) - 1].place(x=yellow_start_label_x, y=yellow_start_label_y)512 self.yellow_coin_position[int(coin_number) - 1] = 27513 self.window.update()514 time.sleep(0.2)515 def sky_blue_circle_start_position(self,coin_number):516 self.make_canvas.delete(self.made_sky_blue_coin[int(coin_number)-1])517 self.made_sky_blue_coin[int(coin_number)-1] = self.make_canvas.create_oval(100+240,340+(40*5)-5,100+240+40,340+(40*6)-5,fill="#04d9ff",width=3)518 self.sky_blue_number_label[int(coin_number)-1].place_forget()519 sky_blue_start_label_x = 100+240 + 10520 sky_blue_start_label_y = 340+(40*5)-5 + 5521 self.sky_blue_number_label[int(coin_number) - 1].place(x=sky_blue_start_label_x, y=sky_blue_start_label_y)522 self.sky_blue_coin_position[int(coin_number) - 1] = 40523 self.window.update()524 time.sleep(0.2)525 def main_controller(self, color_coin, coin_number):526 processing_result = self.input_filtering(coin_number)# Value filtering527 if processing_result is True:528 pass529 else:530 messagebox.showerror("Wrong input number","Please input the coin number between 1 to 4")531 return532 if color_coin == "red":533 self.block_value_predict[0][3]['state'] = DISABLED534 if self.move_red_counter == 106:535 messagebox.showwarning("Destination reached","Reached at the destination")536 elif self.red_coin_position[int(coin_number)-1] == -1 and self.move_red_counter == 6:537 self.red_circle_start_position(coin_number)538 self.red_coord_store[int(coin_number) - 1] = 1539 elif self.red_coin_position[int(coin_number)-1] > -1:540 take_coord = self.make_canvas.coords(self.made_red_coin[int(coin_number)-1])541 red_start_label_x = take_coord[0] + 10542 red_start_label_y = take_coord[1] + 5543 self.red_number_label[int(coin_number) - 1].place(x=red_start_label_x, y=red_start_label_y)544 if self.red_coin_position[int(coin_number)-1]+self.move_red_counter<=106:545 self.red_coin_position[int(coin_number)-1] = self.motion_of_coin(self.red_coin_position[int(coin_number) - 1],self.made_red_coin[int(coin_number)-1],self.red_number_label[int(coin_number)-1],red_start_label_x,red_start_label_y,"red",self.move_red_counter)546 else:547 messagebox.showerror("Not possible","Sorry, not permitted")548 self.block_value_predict[0][3]['state'] = NORMAL549 return550 if self.red_coin_position[int(coin_number)-1]==22 or self.red_coin_position[int(coin_number)-1]==9 or self.red_coin_position[int(coin_number)-1]==48 or self.red_coin_position[int(coin_number)-1]==35 or self.red_coin_position[int(coin_number)-1]==14 or self.red_coin_position[int(coin_number)-1]==27 or self.red_coin_position[int(coin_number)-1]==40:551 pass552 else:553 if self.red_coin_position[int(coin_number) - 1] < 100:554 self.coord_overlap(self.red_coin_position[int(coin_number)-1],color_coin, self.move_red_counter)555 self.red_coord_store[int(coin_number)-1] = self.red_coin_position[int(coin_number)-1]556 else:557 messagebox.showerror("Wrong choice","Sorry, Your coin in not permitted to travel")558 self.block_value_predict[0][3]['state'] = NORMAL559 return560 self.block_value_predict[0][1]['state'] = NORMAL561 elif color_coin == "green":562 self.block_value_predict[3][3]['state'] = DISABLED563 if self.move_green_counter == 106:564 messagebox.showwarning("Destination reached","Reached at the destination")565 elif self.green_coin_position[int(coin_number) - 1] == -1 and self.move_green_counter == 6:566 self.green_circle_start_position(coin_number)567 self.green_coord_store[int(coin_number) - 1] = 14568 elif self.green_coin_position[int(coin_number) - 1] > -1:569 take_coord = self.make_canvas.coords(self.made_green_coin[int(coin_number) - 1])570 green_start_label_x = take_coord[0] + 10571 green_start_label_y = take_coord[1] + 5572 self.green_number_label[int(coin_number) - 1].place(x=green_start_label_x, y=green_start_label_y)573 if self.green_coin_position[int(coin_number) - 1] + self.move_green_counter <= 106:574 self.green_coin_position[int(coin_number) - 1] = self.motion_of_coin(self.green_coin_position[int(coin_number) - 1], self.made_green_coin[int(coin_number) - 1], self.green_number_label[int(coin_number) - 1], green_start_label_x, green_start_label_y, "green", self.move_green_counter)575 else:576 messagebox.showerror("Not possible","No path available")577 self.block_value_predict[3][3]['state'] = NORMAL578 return579 if self.green_coin_position[int(coin_number)-1]==22 or self.green_coin_position[int(coin_number)-1]==9 or self.green_coin_position[int(coin_number)-1]==48 or self.green_coin_position[int(coin_number)-1]==35 or self.green_coin_position[int(coin_number)-1]==1 or self.green_coin_position[int(coin_number)-1]==27 or self.green_coin_position[int(coin_number)-1]==40:580 pass581 else:582 if self.green_coin_position[int(coin_number) - 1] < 100:583 self.coord_overlap(self.green_coin_position[int(coin_number) - 1],color_coin, self.move_green_counter)584 self.green_coord_store[int(coin_number) - 1] = self.green_coin_position[int(coin_number) - 1]585 else:586 messagebox.showerror("Wrong choice", "Sorry, Your coin in not permitted to travel")587 self.block_value_predict[3][3]['state'] = NORMAL588 return589 self.block_value_predict[3][1]['state'] = NORMAL590 elif color_coin == "yellow":591 self.block_value_predict[2][3]['state'] = DISABLED592 if self.move_yellow_counter == 106:593 messagebox.showwarning("Destination reached","Reached at the destination")594 elif self.yellow_coin_position[int(coin_number) - 1] == -1 and self.move_yellow_counter == 6:595 self.yellow_circle_start_position(coin_number)596 self.yellow_coord_store[int(coin_number) - 1] = 27597 elif self.yellow_coin_position[int(coin_number) - 1] > -1:598 take_coord = self.make_canvas.coords(self.made_yellow_coin[int(coin_number) - 1])599 yellow_start_label_x = take_coord[0] + 10600 yellow_start_label_y = take_coord[1] + 5601 self.yellow_number_label[int(coin_number) - 1].place(x=yellow_start_label_x, y=yellow_start_label_y)602 if self.yellow_coin_position[int(coin_number) - 1] + self.move_yellow_counter <= 106:603 self.yellow_coin_position[int(coin_number) - 1] = self.motion_of_coin(self.yellow_coin_position[int(coin_number) - 1], self.made_yellow_coin[int(coin_number) - 1], self.yellow_number_label[int(coin_number) - 1], yellow_start_label_x, yellow_start_label_y, "yellow", self.move_yellow_counter)604 else:605 messagebox.showerror("Not possible","No path available")606 self.block_value_predict[2][3]['state'] = NORMAL607 return608 if self.yellow_coin_position[int(coin_number)-1]==22 or self.yellow_coin_position[int(coin_number)-1]==9 or self.yellow_coin_position[int(coin_number)-1]==48 or self.yellow_coin_position[int(coin_number)-1]==35 or self.yellow_coin_position[int(coin_number)-1]==1 or self.yellow_coin_position[int(coin_number)-1]==14 or self.yellow_coin_position[int(coin_number)-1]==40:609 pass610 else:611 if self.yellow_coin_position[int(coin_number) - 1] < 100:612 self.coord_overlap(self.yellow_coin_position[int(coin_number) - 1],color_coin, self.move_yellow_counter)613 self.yellow_coord_store[int(coin_number) - 1] = self.yellow_coin_position[int(coin_number) - 1]614 else:615 messagebox.showerror("Wrong choice", "Sorry, Your coin in not permitted to travel")616 self.block_value_predict[2][3]['state'] = NORMAL617 return618 self.block_value_predict[2][1]['state'] = NORMAL619 elif color_coin == "sky_blue":620 self.block_value_predict[1][3]['state'] = DISABLED621 if self.move_red_counter == 106:622 messagebox.showwarning("Destination reached","Reached at the destination")623 elif self.sky_blue_coin_position[int(coin_number) - 1] == -1 and self.move_sky_blue_counter == 6:624 self.sky_blue_circle_start_position(coin_number)625 self.sky_blue_coord_store[int(coin_number) - 1] = 40626 elif self.sky_blue_coin_position[int(coin_number) - 1] > -1:627 take_coord = self.make_canvas.coords(self.made_sky_blue_coin[int(coin_number) - 1])628 sky_blue_start_label_x = take_coord[0] + 10629 sky_blue_start_label_y = take_coord[1] + 5630 self.sky_blue_number_label[int(coin_number) - 1].place(x=sky_blue_start_label_x, y=sky_blue_start_label_y)631 if self.sky_blue_coin_position[int(coin_number) - 1] + self.move_sky_blue_counter <= 106:632 self.sky_blue_coin_position[int(coin_number) - 1] = self.motion_of_coin(self.sky_blue_coin_position[int(coin_number) - 1], self.made_sky_blue_coin[int(coin_number) - 1], self.sky_blue_number_label[int(coin_number) - 1], sky_blue_start_label_x, sky_blue_start_label_y, "sky_blue", self.move_sky_blue_counter)633 else:634 messagebox.showerror("Not possible","No path available")635 self.block_value_predict[1][3]['state'] = NORMAL636 return637 if self.sky_blue_coin_position[int(coin_number)-1]==22 or self.sky_blue_coin_position[int(coin_number)-1]==9 or self.sky_blue_coin_position[int(coin_number)-1]==48 or self.sky_blue_coin_position[int(coin_number)-1]==35 or self.sky_blue_coin_position[int(coin_number)-1]==1 or self.sky_blue_coin_position[int(coin_number)-1]==14 or self.sky_blue_coin_position[int(coin_number)-1]==27:638 pass639 else:640 if self.sky_blue_coin_position[int(coin_number) - 1] < 100:641 self.coord_overlap(self.sky_blue_coin_position[int(coin_number) - 1],color_coin, self.move_sky_blue_counter)642 self.sky_blue_coord_store[int(coin_number) - 1] = self.sky_blue_coin_position[int(coin_number) - 1]643 else:644 messagebox.showerror("Wrong choice", "Sorry, Your coin in not permitted to travel")645 self.block_value_predict[1][3]['state'] = NORMAL646 return647 self.block_value_predict[1][1]['state'] = NORMAL648 print(self.red_coord_store)649 print(self.green_coord_store)650 print(self.yellow_coord_store)651 print(self.sky_blue_coord_store)652 permission_granted_to_proceed = True653 if color_coin == "red" and self.red_coin_position[int(coin_number)-1] == 106:654 permission_granted_to_proceed = self.check_winner_and_runner(color_coin)655 elif color_coin == "green" and self.green_coin_position[int(coin_number)-1] == 106:656 permission_granted_to_proceed = self.check_winner_and_runner(color_coin)657 elif color_coin == "yellow" and self.yellow_coin_position[int(coin_number)-1] == 106:658 permission_granted_to_proceed = self.check_winner_and_runner(color_coin)659 elif color_coin == "sky_blue" and self.sky_blue_coin_position[int(coin_number)-1] == 106:660 permission_granted_to_proceed = self.check_winner_and_runner(color_coin)661 if permission_granted_to_proceed:# if that is False, Game is over and not proceed more662 self.make_command()663 def motion_of_coin(self,counter_coin,specific_coin,number_label,number_label_x ,number_label_y,color_coin,path_counter):664 number_label.place(x=number_label_x,y=number_label_y)665 while True:666 if path_counter == 0:667 break668 elif (counter_coin == 51 and color_coin == "red") or (counter_coin==12 and color_coin == "green") or (counter_coin == 25 and color_coin == "yellow") or (counter_coin == 38 and color_coin == "sky_blue") or counter_coin>=100:669 if counter_coin<100:670 counter_coin=100671 counter_coin = self.under_room_traversal_control(specific_coin, number_label, number_label_x, number_label_y, path_counter, counter_coin, color_coin)672 if counter_coin == 106:673 messagebox.showinfo("Destination reached","Congrats! You now at the destination")674 if path_counter == 6:675 self.six_with_overlap = 1676 else:677 self.time_for -= 1678 break679 counter_coin += 1680 path_counter -=1681 number_label.place_forget()682 print(counter_coin)683 if counter_coin<=5:684 self.make_canvas.move(specific_coin, 40, 0)685 number_label_x+=40686 elif counter_coin == 6:687 self.make_canvas.move(specific_coin, 40, -40)688 number_label_x += 40689 number_label_y-=40690 elif 6< counter_coin <=11:691 self.make_canvas.move(specific_coin, 0, -40)692 number_label_y -= 40693 elif counter_coin <=13:694 self.make_canvas.move(specific_coin, 40, 0)695 number_label_x += 40696 elif counter_coin <=18:697 self.make_canvas.move(specific_coin, 0, 40)698 number_label_y += 40699 elif counter_coin == 19:700 self.make_canvas.move(specific_coin, 40, 40)701 number_label_x += 40702 number_label_y += 40703 elif counter_coin <=24:704 self.make_canvas.move(specific_coin, 40, 0)705 number_label_x += 40706 elif counter_coin <=26:707 self.make_canvas.move(specific_coin, 0, 40)708 number_label_y += 40709 elif counter_coin <=31:710 self.make_canvas.move(specific_coin, -40, 0)711 number_label_x -= 40712 elif counter_coin == 32:713 self.make_canvas.move(specific_coin, -40, 40)714 number_label_x -= 40715 number_label_y += 40716 elif counter_coin <= 37:717 self.make_canvas.move(specific_coin, 0, 40)718 number_label_y += 40719 elif counter_coin <= 39:720 self.make_canvas.move(specific_coin, -40, 0)721 number_label_x -= 40722 elif counter_coin <= 44:723 self.make_canvas.move(specific_coin, 0, -40)724 number_label_y -= 40725 elif counter_coin == 45:726 self.make_canvas.move(specific_coin, -40, -40)727 number_label_x -= 40728 number_label_y -= 40729 elif counter_coin <= 50:730 self.make_canvas.move(specific_coin, -40, 0)731 number_label_x -= 40732 elif 50< counter_coin <=52:733 self.make_canvas.move(specific_coin, 0, -40)734 number_label_y -= 40735 elif counter_coin == 53:736 self.make_canvas.move(specific_coin, 40, 0)737 number_label_x += 40738 counter_coin = 1739 number_label.place_forget()740 number_label.place(x=number_label_x, y=number_label_y)741 self.window.update()742 time.sleep(0.2)743 return counter_coin744 # For same position, previous coin deleted and set to the room745 def coord_overlap(self, counter_coin, color_coin, path_to_traverse_before_overlap):746 if color_coin!="red":747 for take_coin_number in range(len(self.red_coord_store)):748 if self.red_coord_store[take_coin_number] == counter_coin:749 if path_to_traverse_before_overlap == 6:750 self.six_with_overlap=1751 else:752 self.time_for-=1753 self.make_canvas.delete(self.made_red_coin[take_coin_number])754 self.red_number_label[take_coin_number].place_forget()755 self.red_coin_position[take_coin_number] = -1756 self.red_coord_store[take_coin_number] = -1757 if take_coin_number == 0:758 remade_coin = self.make_canvas.create_oval(100+40, 15+40, 100+40+40, 15+40+40, width=3, fill="red", outline="black")759 self.red_number_label[take_coin_number].place(x=100 + 40 + 10, y=15 + 40 + 5)760 elif take_coin_number == 1:761 remade_coin = self.make_canvas.create_oval(100+40+60+60, 15 + 40, 100+40+60+60+40, 15 + 40 + 40, width=3, fill="red", outline="black")762 self.red_number_label[take_coin_number].place(x=100 + 40 + 60 +60 + 10, y=15 + 40 + 5)763 elif take_coin_number == 2:764 remade_coin = self.make_canvas.create_oval(100 + 40 + 60 + 60, 15 + 40 + 100, 100 + 40 + 60 + 60 + 40, 15 + 40 + 40 + 100, width=3, fill="red", outline="black")765 self.red_number_label[take_coin_number].place(x=100 + 40 + 60 + 60 + 10, y=15 + 40 + 100 + 5)766 else:767 remade_coin = self.make_canvas.create_oval(100 + 40, 15 + 40+100, 100 + 40 + 40, 15 + 40 + 40+100, width=3,fill="red", outline="black")768 self.red_number_label[take_coin_number].place(x=100 + 40 + 10, y=15 + 40 + 100 + 5)769 self.made_red_coin[take_coin_number]=remade_coin770 if color_coin != "green":771 for take_coin_number in range(len(self.green_coord_store)):772 if self.green_coord_store[take_coin_number] == counter_coin:773 if path_to_traverse_before_overlap == 6:774 self.six_with_overlap = 1775 else:776 self.time_for-=1777 self.make_canvas.delete(self.made_green_coin[take_coin_number])778 self.green_number_label[take_coin_number].place_forget()779 self.green_coin_position[take_coin_number] = -1780 self.green_coord_store[take_coin_number] = -1781 if take_coin_number == 0:782 remade_coin = self.make_canvas.create_oval(340+(40*3)+40, 15 + 40, 340+(40*3)+40 + 40, 15 + 40 + 40, width=3, fill="#00FF00", outline="black")783 self.green_number_label[take_coin_number].place(x=340 + (40 * 3) + 40 + 10, y=15 + 40 + 5)784 elif take_coin_number == 1:785 remade_coin = self.make_canvas.create_oval(340+(40*3)+40+ 60 + 40+20, 15 + 40, 340+(40*3)+40 + 60 + 40 + 40+20, 15 + 40 + 40, width=3, fill="#00FF00", outline="black")786 self.green_number_label[take_coin_number].place(x=340 + (40 * 3) + 40 + 40 + 60 + 30, y=15 + 40 + 5)787 elif take_coin_number == 2:788 remade_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40 + 60 + 40 + 20, 15 + 40 + 100, 340 + (40 * 3) + 40 + 60 + 40 + 40 + 20, 15 + 40 + 40 + 100, width=3, fill="#00FF00", outline="black")789 self.green_number_label[take_coin_number].place(x=340 + (40 * 3) + 40 + 40 + 60 + 30, y=15 + 40 + 100 + 5)790 else:791 remade_coin = self.make_canvas.create_oval(340+(40*3)+40, 15 + 40 + 100, 340+(40*3)+40 + 40, 15 + 40 + 40 + 100, width=3, fill="#00FF00", outline="black")792 self.green_number_label[take_coin_number].place(x=340+(40*3) + 40 + 10, y=15 + 40 + 100 + 5)793 self.made_green_coin[take_coin_number] = remade_coin794 if color_coin != "yellow":795 for take_coin_number in range(len(self.yellow_coord_store)):796 if self.yellow_coord_store[take_coin_number] == counter_coin:797 if path_to_traverse_before_overlap == 6:798 self.six_with_overlap = 1799 else:800 self.time_for -= 1801 self.make_canvas.delete(self.made_yellow_coin[take_coin_number])802 self.yellow_number_label[take_coin_number].place_forget()803 self.yellow_coin_position[take_coin_number] = -1804 self.yellow_coord_store[take_coin_number] = -1805 if take_coin_number == 0:806 remade_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40, 340+80+15, 340 + (40 * 3) + 40 + 40, 340+80+40+15, width=3, fill="yellow", outline="black")807 self.yellow_number_label[take_coin_number].place(x=340+(40*3) + 40 + 10, y=30 + (40*6)+(40*3)+40+10)808 elif take_coin_number == 1:809 remade_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40 + 60 + 40 + 20, 340+80+15, 340 + (40 * 3) + 40 + 60 + 40 + 40+20, 340+80+40+15, width=3, fill="yellow", outline="black")810 self.yellow_number_label[take_coin_number].place(x=340+(40*3)+ 40 + 40+ 60 + 30, y=30 + (40*6)+(40*3)+40+10)811 elif take_coin_number == 2:812 remade_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40 + 60 + 40 + 20, 340 + 80 + 60 + 40 + 15, 340 + (40 * 3) + 40 + 60 + 40 + 40 + 20, 340 + 80 + 60 + 40 + 40 + 15, width=3, fill="yellow", outline="black")813 self.yellow_number_label[take_coin_number].place(x=340+(40*3)+ 40 + 40+ 60 + 30, y=30 + (40*6)+(40*3)+40+100+10)814 else:815 remade_coin = self.make_canvas.create_oval(340 + (40 * 3) + 40, 340+80+60+40+15, 340 + (40 * 3) + 40 + 40,340+80+60+40+40+15, width=3, fill="yellow", outline="black")816 self.yellow_number_label[take_coin_number].place(x=340 + (40 * 3) + 40 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 100 + 10)817 self.made_yellow_coin[take_coin_number] = remade_coin818 if color_coin != "sky_blue":819 for take_coin_number in range(len(self.sky_blue_coord_store)):820 if self.sky_blue_coord_store[take_coin_number] == counter_coin:821 if path_to_traverse_before_overlap == 6:822 self.six_with_overlap = 1823 else:824 self.time_for -= 1825 self.make_canvas.delete(self.made_sky_blue_coin[take_coin_number])826 self.sky_blue_number_label[take_coin_number].place_forget()827 self.sky_blue_coin_position[take_coin_number] = -1828 self.sky_blue_coord_store[take_coin_number]=-1829 if take_coin_number == 0:830 remade_coin = self.make_canvas.create_oval(100 + 40, 340+80+15, 100 + 40 + 40, 340+80+40+15, width=3, fill="#04d9ff", outline="black")831 self.sky_blue_number_label[take_coin_number].place(x=100+40+10, y=30 + (40*6)+(40*3)+40+10)832 elif take_coin_number == 1:833 remade_coin = self.make_canvas.create_oval(100 + 40 + 60 + 40+20, 340+80+15, 100 + 40 + 60 + 40 + 40+20, 340+80+40+15, width=3, fill="#04d9ff", outline="black")834 self.sky_blue_number_label[take_coin_number].place(x=100 + 40 + 60 +60 + 10, y=30 + (40*6)+(40*3)+40+10)835 elif take_coin_number == 2:836 remade_coin = self.make_canvas.create_oval(100 + 40 + 60 + 40 + 20, 340 + 80 + 60 + 40 + 15, 100 + 40 + 60 + 40 + 40 + 20, 340 + 80 + 60 + 40 + 40 + 15, width=3, fill="#04d9ff", outline="black")837 self.sky_blue_number_label[take_coin_number].place(x=100 + 40 + 60 + 60 + 10, y=30 + (40 * 6) + (40 * 3) + 40 + 60 + 40 + 10)838 else:839 remade_coin = self.make_canvas.create_oval( 100 + 40, 340+80+60+40+15, 100 + 40 + 40, 340+80+60+40+40+15, width=3, fill="#04d9ff", outline="black")840 self.sky_blue_number_label[take_coin_number].place(x=100+40+10, y=30 + (40*6)+(40*3)+40+60+40+10)841 self.made_sky_blue_coin[take_coin_number] = remade_coin842 def under_room_traversal_control(self,specific_coin,number_label,number_label_x,number_label_y,path_counter,counter_coin,color_coin):843 if color_coin == "red" and counter_coin >= 100:844 if int(counter_coin)+int(path_counter)<=106:845 counter_coin = self.room_red_traversal(specific_coin, number_label, number_label_x, number_label_y, path_counter, counter_coin)846 elif color_coin == "green" and counter_coin >= 100:847 if int(counter_coin) + int(path_counter) <= 106:848 counter_coin = self.room_green_traversal(specific_coin, number_label, number_label_x, number_label_y,path_counter,counter_coin)849 elif color_coin == "yellow" and counter_coin >= 100:850 if int(counter_coin) + int(path_counter) <= 106:851 counter_coin = self.room_yellow_traversal(specific_coin, number_label, number_label_x, number_label_y,path_counter,counter_coin)852 elif color_coin == "sky_blue" and counter_coin >= 100:853 if int(counter_coin) + int(path_counter) <= 106:854 counter_coin = self.room_sky_blue_traversal(specific_coin, number_label, number_label_x, number_label_y,path_counter,counter_coin)855 return counter_coin856 def room_red_traversal(self, specific_coin, number_label, number_label_x, number_label_y, path_counter, counter_coin):857 while path_counter>0:858 counter_coin += 1859 path_counter -= 1860 self.make_canvas.move(specific_coin, 40, 0)861 number_label_x+=40862 number_label.place(x=number_label_x,y=number_label_y)863 self.window.update()864 time.sleep(0.2)865 return counter_coin866 def room_green_traversal(self, specific_coin, number_label, number_label_x, number_label_y, path_counter, counter_coin):867 while path_counter > 0:868 counter_coin += 1869 path_counter -= 1870 self.make_canvas.move(specific_coin, 0, 40)871 number_label_y += 40872 number_label.place(x=number_label_x, y=number_label_y)873 self.window.update()874 time.sleep(0.2)875 return counter_coin876 def room_yellow_traversal(self, specific_coin, number_label, number_label_x, number_label_y,path_counter,counter_coin):877 while path_counter > 0:878 counter_coin += 1879 path_counter -= 1880 self.make_canvas.move(specific_coin, -40, 0)881 number_label_x -= 40882 number_label.place(x=number_label_x, y=number_label_y)883 self.window.update()884 time.sleep(0.2)885 return counter_coin886 def room_sky_blue_traversal(self, specific_coin, number_label, number_label_x, number_label_y,path_counter,counter_coin):887 while path_counter > 0:888 counter_coin += 1889 path_counter -= 1890 self.make_canvas.move(specific_coin, 0, -40)891 number_label_y -= 40892 number_label.place(x=number_label_x, y=number_label_y)893 self.window.update()894 time.sleep(0.2)895 return counter_coin896 def check_winner_and_runner(self,color_coin):897 destination_reached = 0 # Check for all specific color coins898 if color_coin == "red":899 temp_store = self.red_coord_store900 temp_delete = 0# Player index901 elif color_coin == "green":902 temp_store = self.green_coord_store903 temp_delete = 3# Player index904 elif color_coin == "yellow":905 temp_store = self.yellow_coord_store906 temp_delete = 2# Player index907 else:908 temp_store = self.sky_blue_coord_store909 temp_delete = 1# Player index910 for take in temp_store:911 if take == 106:912 destination_reached = 1913 else:914 destination_reached = 0915 break916 if destination_reached == 1:# If all coins in block reach to the destination, winner and runner check917 self.take_permission += 1918 if self.take_permission == 1:# Winner check919 messagebox.showinfo("Winner","Congrats! You are the winner")920 elif self.take_permission == 2:# 1st runner check921 messagebox.showinfo("Winner", "Wow! You are 1st runner")922 elif self.take_permission == 3:# 2nd runner check923 messagebox.showinfo("Winner", "Wow! You are 2nd runner")924 self.block_value_predict[temp_delete][1]['state'] = DISABLED925 self.total_people_play.remove(temp_delete)926 if len(self.total_people_play) == 1:927 messagebox.showinfo("Game Over","Good bye!!!!")928 self.block_value_predict[0][1]['state'] = DISABLED929 return False930 else:931 self.time_for-=1932 else:933 print("Winner not decided")934 return True935 # Input value checking936 def input_filtering(self,coin_number):937 try:938 if (4>=int(coin_number)>=1) or type(coin_number) == int:939 return True940 else:941 return False942 except:943 return False944if __name__ == '__main__':945 window = Tk()946 window.geometry("800x630")947 window.maxsize(800,630)948 window.minsize(800,630)949 window.title("Play Ludo super")950 window.iconbitmap("Images/ludo_icon.ico")951 block_six_side = ImageTk.PhotoImage(Image.open("Images/6_block.png").resize((33, 33), Image.ANTIALIAS))952 block_five_side = ImageTk.PhotoImage(Image.open("Images/5_block.png").resize((33, 33), Image.ANTIALIAS))953 block_four_side = ImageTk.PhotoImage(Image.open("Images/4_block.png").resize((33, 33), Image.ANTIALIAS))954 block_three_side = ImageTk.PhotoImage(Image.open("Images/3_block.png").resize((33, 33), Image.ANTIALIAS))955 block_two_side = ImageTk.PhotoImage(Image.open("Images/2_block.png").resize((33, 33), Image.ANTIALIAS))956 block_one_side = ImageTk.PhotoImage(Image.open("Images/1_block.png").resize((33, 33), Image.ANTIALIAS))957 Ludo(window,block_six_side,block_five_side,block_four_side,block_three_side,block_two_side,block_one_side)...
Searching_Algo_Visualizer.py
Source:Searching_Algo_Visualizer.py
1 # Searching Algorithm Visualizer #2from tkinter import *3from tkinter import messagebox4from PIL import Image,ImageTk5import time6class Initialization:7 def __init__(self,root):8 self.window= root9 self.store=[10,20,30,40,50,60,70,80,90,100]10 self.search_position_linear = -111 self.search_position_binary = -112 self.start_binary = 013 self.end_binary = 914 self.linear_indicator = 015 self.binary_indicator = 016 self.search_value_take = None17 self.make_canvas = Canvas(self.window,bg="chocolate",width=900,height=600,relief=RAISED,bd=4)18 self.make_canvas.pack()19 heading = lambda: Label(self.make_canvas,text="Searching Algo Visualizer",bg="chocolate",fg="yellow",font=("Arial",25,"bold","italic")).place(x=250,y=15)20 heading()21class Setup(Initialization):22 def __init__(self, root):23 super(Setup,self).__init__(root)24 self.__search_and_index_label_indicate()25 self.__two_array_maker()26 self.__array_void_containers_and_index_maker()27 self.make_arrow()28 self.__make_correct_wrong()29 self.__steps_label()30 def __search_and_index_label_indicate(self):31 Label(self.make_canvas, text="Linear\nSearch", font=("Arial",30,"bold"), bg="chocolate", fg="gold").place(x=40, y=150 + 50)32 Label(self.make_canvas, text="Binary\nSearch", font=("Arial", 30, "bold"), bg="chocolate", fg="gold").place(x=40, y=150 + 50+250)33 Label(self.make_canvas, text="Index no.", font=("Arial", 13, "bold"), bg="chocolate", fg="brown").place(x=70, y=150 + 10)34 Label(self.make_canvas, text="Index no.", font=("Arial", 13, "bold"), bg="chocolate", fg="brown").place(x=70, y=150 + 10 + 250)35 def __two_array_maker(self):36 self.make_canvas.create_line(200, 150+50, 718+3, 150+50,width=3,fill="blue")37 self.make_canvas.create_line(200, 206+50, 718+3, 206+50, width=3,fill="blue")38 self.make_canvas.create_line(200, 450, 718 + 3, 450, width=3, fill="blue")39 self.make_canvas.create_line(200, 506, 718 + 3, 506, width=3, fill="blue")40 def __array_void_containers_and_index_maker(self):41 start_x=20142 Label(self.make_canvas,text="-1",font=("Arial",20,"bold","italic"),bg="chocolate",fg="blue").place(x=start_x-52,y=203-50)43 Label(self.make_canvas,text="-1",font=("Arial",20,"bold","italic"),bg="chocolate",fg="blue").place(x=start_x-52,y=453-50)44 for i in range(10):45 self.make_canvas.create_rectangle(start_x,203,start_x+50,253,width=3,outline="#00FF00")46 Label(self.make_canvas,text=(i+1)*10,font=("Arial",15,"bold","italic"),bg="chocolate",fg="yellow").place(x=start_x+10,y=203+10)47 # Up array index maker48 Label(self.make_canvas,text=i,font=("Arial",20,"bold","italic"),bg="chocolate",fg="blue").place(x=start_x+15,y=203-50)49 50 self.make_canvas.create_rectangle(start_x,453,start_x+50,503,width=3,outline="#00FF00")51 Label(self.make_canvas,text=(i+1)*10,font=("Arial",15,"bold","italic"),bg="chocolate",fg="yellow").place(x=start_x+10,y=453+10)52 # Down array index maker53 Label(self.make_canvas,text=i,font=("Arial",20,"bold","italic"),bg="chocolate",fg="blue").place(x=start_x+15,y=453-50)54 start_x+=5255 def make_arrow(self):56 points_linear = (170,100+50, 170-20,(100+60)/2+50, 170-10,(100+60)/2+50, 170-10,60+50, 170+10,60+50, 170+10,(100+60)/2+50, 170+20,(100+60)/2+50)57 self.linear_indicator = self.make_canvas.create_polygon(points_linear,width=3,fill="#0FFF0F",outline="black")58 points_binary = (170,100+50+250, 170-20,(100+60)/2+50+250, 170-10,(100+60)/2+50+250, 170-10,60+50+250, 170+10,60+50+250, 170+10,(100+60)/2+50+250, 170+20,(100+60)/2+50+250)59 self.binary_indicator = self.make_canvas.create_polygon(points_binary,width=3,fill="#0FFF0F",outline="black")60 def __make_correct_wrong(self):61 global img_correct, img_wrong62 self.pic_correct_x=15563 self.pic_wrong_x=15564 img_correct = ImageTk.PhotoImage(Image.open("Images/correct.png").resize((30,30),Image.ANTIALIAS))65 self.pic_correct = Label(self.make_canvas,image=img_correct,bg="chocolate")66 img_wrong = ImageTk.PhotoImage(Image.open("Images/wrong.png").resize((30, 30), Image.ANTIALIAS))67 self.pic_wrong = Label(self.make_canvas, image=img_wrong, bg="chocolate")68 def __steps_label(self):69 self.binary_step_counter = 070 self.linear_step_counter = 071 self.step_linear = Label(self.make_canvas,text="Steps: "+ str(self.binary_step_counter),font=("Arial",20,"bold"),bg="chocolate",fg="gold")72 self.step_linear.place(x=750,y=210)73 self.step_binary = Label(self.make_canvas, text="Steps: " + str(self.linear_step_counter), font=("Arial", 20, "bold"), bg="chocolate", fg="gold")74 self.step_binary.place(x=750, y=210+250)75 # According to the instruction change arrow position76 def arrow_movement_controller(self,counter,direction,arrow_particular):77 try:78 num = 52 * counter79 while num:80 if direction == 0:81 if arrow_particular == "linear":82 self.make_canvas.move(self.linear_indicator, -1, 0)83 else:84 self.make_canvas.move(self.binary_indicator, -1, 0)85 self.pic_wrong_x -= 186 self.pic_correct_x -= 187 else:88 if arrow_particular == "linear":89 self.make_canvas.move(self.linear_indicator, 1, 0)90 else:91 self.make_canvas.move(self.binary_indicator, 1, 0)92 self.pic_wrong_x += 193 self.pic_correct_x += 194 self.window.update()95 time.sleep(0.01)96 num -= 197 except:98 print("Force stop error")99class Functionality(Setup):100 def __init__(self, root):101 super(Functionality, self).__init__(root)102 self.__introduction_btn()103 def __introduction_btn(self):104 self.search_val_btn = Button(self.window, text="Search a value", font=("Arial", 25, "bold", "italic"), bg="black", fg="green", relief=RAISED, bd=7, command=self.__entry_take_forward)105 self.search_val_btn.place(x=50, y=618)106 self.reset_btn = Button(self.window, text="Reset", font=("Arial", 25, "bold", "italic"), bg="black", fg="green", relief=RAISED, bd=7, command=self.__reset_all, state=DISABLED)107 self.reset_btn.place(x=700, y=618)108 # Take entry from user and forward109 def __entry_take_forward(self):110 self.search_value_take = Entry(self.window, font=("Arial", 25, "bold", "italic"), fg="green", relief=SUNKEN, bd=7, width=5)111 self.search_value_take.place(x=350, y=630)112 self.search_value_take.focus()113 self.search_val_activation = Button(self.window, text="Search Value", font=("Arial", 18, "bold", "italic"), bg="gold", fg="green", relief=RAISED, bd=5, command=self.__give_searching_control)114 self.search_val_activation.place(x=500, y=630)115 # Linear and Binary Search Control give116 def __give_searching_control(self):117 try:118 self.search_val_btn['state'] = DISABLED119 self.search_val_activation['state'] = DISABLED120 # Searching value filtering121 try:122 if int(self.search_value_take.get()):123 pass124 except:125 messagebox.showerror("Input error","Please give a integer value to input")126 self.search_val_btn['state'] = NORMAL127 return128 self.__linear_search_it()129 # After linear search customization130 if 9>=self.search_position_linear>=0:131 self.pic_correct.place_forget()132 self.linear_conformation = Label(self.make_canvas,text="Found",font=("Arial",20,"bold"),bg="chocolate",fg="brown")133 self.linear_conformation.place(x=self.pic_correct_x-15,y=70)134 else:135 self.make_canvas.move(self.linear_indicator,-(52*2),0)136 self.make_canvas.itemconfig(self.linear_indicator,fill="red")137 self.window.update()138 self.linear_conformation = Label(self.make_canvas, text="Not found searching value in this array", font=("Arial", 20, "bold"), bg="chocolate", fg="brown")139 self.linear_conformation.place(x=self.pic_correct_x - 400, y=70)140 # Default position set141 self.pic_correct_x=155142 self.pic_correct_y = 70+250143 self.pic_wrong_x = 155144 self.pic_wrong_y = 70+250145 self.__binary_search_it()146 # After binary search customization147 if self.start_binary<=self.end_binary:148 self.pic_correct.place_forget()149 self.binary_conformation = Label(self.make_canvas,text="Found",font=("Arial",20,"bold"),bg="chocolate",fg="brown")150 self.binary_conformation.place(x=self.pic_correct_x-15,y=70+250)151 else:152 self.make_canvas.itemconfig(self.binary_indicator,fill="Red")153 self.binary_conformation = Label(self.make_canvas, text="Not found searching value", font=("Arial", 20, "bold"), bg="chocolate", fg="brown")154 self.binary_conformation.place(x=self.pic_correct_x - 200, y=70+250)155 self.reset_btn['state'] = NORMAL156 except:157 print("Force stop error")158 # Linear Search Process Control159 def __linear_search_it(self):160 try:161 if self.search_position_linear>9:162 messagebox.showerror("Not found","Searching value not found")163 # Initial Condition164 elif self.search_position_linear == -1:165 self.arrow_movement_controller(1,1,"linear")166 self.search_position_linear += 1167 self.linear_step_counter += 1168 self.step_linear['text'] = "Steps: "+ str(self.linear_step_counter)169 self.__linear_search_it()170 # Value get condition171 elif self.store[self.search_position_linear] == int(self.search_value_take.get()):172 self.pic_correct.place(x=self.pic_correct_x, y=70)173 self.window.update()174 time.sleep(0.5)175 else:176 # Pic Show and forget177 self.pic_wrong.place(x=self.pic_correct_x, y=70)178 self.window.update()179 time.sleep(0.5)180 self.pic_wrong.place_forget()181 # Arrow Movement Control182 self.search_position_linear+=1183 self.arrow_movement_controller(1,1,"linear")184 # Steps Update185 if self.linear_step_counter<10:186 self.linear_step_counter += 1187 self.step_linear['text'] = "Steps: " + str(self.linear_step_counter)188 self.__linear_search_it()189 except:190 print("Force stop error")191 192 def __binary_search_it(self):193 try:194 if self.start_binary<=self.end_binary:195 middle = int((self.start_binary + self.end_binary) / 2)196 if self.search_position_binary == -1:# Initial Condition197 self.arrow_movement_controller(middle + 1, 1,"binary")198 elif self.search_position_binary < middle:199 self.arrow_movement_controller(middle - self.search_position_binary, 1,"binary")200 else:201 self.arrow_movement_controller(self.search_position_binary - middle, 0,"binary")202 self.search_position_binary = middle203 # Steps Update204 self.binary_step_counter += 1205 self.step_binary['text'] = "Steps: " + str(self.binary_step_counter)206 # Value get situation207 if self.store[middle] == int(self.search_value_take.get()):208 self.pic_correct.place(x=self.pic_correct_x, y=70 + 250)209 self.window.update()210 else:211 # Pic Show and forget212 self.pic_wrong.place(x=self.pic_correct_x, y=70 + 250)213 self.window.update()214 time.sleep(0.5)215 self.pic_wrong.place_forget()216 # Range Concept217 if int(self.search_value_take.get()) > self.store[middle]:218 self.start_binary = middle + 1219 else:220 self.end_binary = middle - 1221 self.__binary_search_it()222 else:223 messagebox.showerror("Not found","Searching value not found")224 except:225 print("Force stop error")226 def __reset_all(self):227 # Button state customization228 self.reset_btn['state'] = DISABLED229 self.search_val_btn['state'] = NORMAL230 self.search_val_activation['state'] = NORMAL231 # Default set232 self.pic_correct_x = self.pic_wrong_x = 155233 self.pic_correct_y = self.pic_wrong_y = 70234 self.make_canvas.delete(self.linear_indicator)235 self.make_canvas.delete(self.binary_indicator)236 self.make_arrow()237 self.linear_conformation.place_forget()238 self.binary_conformation.place_forget()239 self.search_position_linear = -1240 self.search_position_binary = -1241 self.start_binary = 0242 self.end_binary = 9243 self.linear_step_counter = 0244 self.binary_step_counter = 0245 self.step_linear['text'] = "Steps: " + str(self.linear_step_counter)246 self.step_binary['text'] = "Steps: " + str(self.binary_step_counter)247if __name__ == '__main__':248 window = Tk()249 window.geometry("900x700")250 window.maxsize(900,700)251 window.minsize(900,700)252 window.title("Searching Visualizer")253 window.config(bg="orange")254 window.iconbitmap("Images/search_icon.ico")255 Functionality(window)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!