-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sprouts.py
727 lines (681 loc) · 26.5 KB
/
Sprouts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
import pygame
import pygame.font
from shapely.geometry import LineString, Point, Polygon
from shapely.ops import nearest_points
from Network import Network
from base64 import b64encode, b64decode
import threading
import Server
import socket
import itertools
import urllib.request
import ssl
import os
import sys
DOT_RADIUS = 8
SCREEN_WIDTH = 1300
SCREEN_HEIGHT = 975
pygame.init()
pygame.font.init()
clock = pygame.time.Clock()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.scrap.init()
# Ugly global variables, will clean up later
local = True
dragging = False
p1_turn = True
available_bool = True
wins = [0,0]
turn_font = pygame.font.SysFont("arial", 30)
smaller_font = pygame.font.SysFont("arial", 28)
win_font = pygame.font.SysFont("arial", 20)
turn_text = None
dot_list = []
line_list = []
cur_line = []
overlap = False
dot_mode = False
cur_display_dot = None
found_loop = False
loop_line_list = []
last_line_in_loop = None
poly_list = []
n = None
# # For making a .exe
# def resource_path(relative_path):
# """ Get absolute path to resource, works for dev and for PyInstaller """
# try:
# # PyInstaller creates a temp folder and stores path in _MEIPASS
# base_path = sys._MEIPASS
# except Exception:
# base_path = os.path.abspath(".")
# return os.path.join(base_path, relative_path)
class Dot():
def __init__(self, da_point, num_con):
self.xval = da_point.x
self.yval = da_point.y
self.point = da_point
self.num_con = num_con
self.marked = False
self.in_or_on_poly = []
self.on_poly = []
def draw_self(self):
pygame.draw.circle(screen, "black", (self.xval, self.yval), DOT_RADIUS)
class Line():
def __init__(self, point_list, start, end):
self.line_string = LineString(point_list)
self.point_list = point_list
self.start = start
self.end = end
self.marked = False
self.prev_line = None
self.adj_lines = []
def find_adj(self):
self.adj_lines.clear()
for line in line_list:
if (line.start == self.start or line.start == self.end or line.end == self.start or line.end == self.end) and line != self:
self.adj_lines.append(line)
def find_start_end(self):
for dot in dot_list:
if dot.point == Point(self.point_list[0]):
self.start = dot
if dot.point == Point(self.point_list[-1]):
self.end = dot
def reverse(self):
temp = self.start
self.start = self.end
self.end = temp
self.point_list.reverse()
self.line_string = LineString(self.point_list)
def remove_consecutive_dups(list):
return [i[0] for i in itertools.groupby(list)]
def remove_start_and_end_overlap(line, start_dot, end_dot):
finished_line = line.copy()
for point in line:
if (abs(point[0] - start_dot.xval) <= DOT_RADIUS - 2) and ((abs(point[1] - start_dot.yval) <= DOT_RADIUS - 2)):
finished_line.remove(point)
else:
break
if len(finished_line) < 1:
return []
for point2 in reversed(line):
if (abs(point2[0] - end_dot.xval) <= DOT_RADIUS - 2) and ((abs(point2[1] - end_dot.yval) <= DOT_RADIUS - 2)):
finished_line.remove(point2)
else:
break
return finished_line
def remove_dot_dups():
global dot_list
new_dot_list = []
for dot in dot_list:
if dot not in new_dot_list:
new_dot_list.append(dot)
dot_list = new_dot_list
def remove_line_dups():
global line_list
new_line_list = []
is_dup = False
for line in line_list:
for new_line in new_line_list:
if line.point_list == new_line.point_list:
is_dup = True
if not is_dup:
new_line_list.append(line)
is_dup = False
line_list = new_line_list
def update_dot_boundings():
for dot in dot_list:
dot.on_poly.clear()
dot.in_or_on_poly.clear()
for poly in poly_list:
if poly.contains(dot.point) or poly.touches(dot.point):
dot.in_or_on_poly.append(poly)
if poly.touches(dot.point):
dot.on_poly.append(poly)
def update_misc():
global available_bool
global turn_text
global wins
global p1_turn
winner = 0
if available_bool:
if p1_turn:
turn_text = turn_font.render("Player 1's Turn", True, (0,0,0))
else:
turn_text = turn_font.render("Player 2's Turn", True, (0,0,0))
else:
if p1_turn:
winner = 1
wins[1] += 1
else:
wins[0] += 1
if winner == n.id:
turn_text = turn_font.render("You Win!", True, (0,0,0))
else:
turn_text = turn_font.render("You Lose!", True, (0,0,0))
def available_moves():
global available_bool
for dot in dot_list:
if dot.num_con < 2:
return True
if dot.num_con == 3:
continue
for con_dot in dot_list:
if dot == con_dot:
continue
if con_dot.num_con == 3:
continue
for poly in dot.in_or_on_poly:
if poly in con_dot.in_or_on_poly:
return True
if len(dot.in_or_on_poly) == 0 and len(con_dot.in_or_on_poly) == 0:
available_bool = True
return
if (len(dot.on_poly) < 2 and (dot.in_or_on_poly == dot.on_poly)) and (len(con_dot.on_poly) < 2 and (con_dot.in_or_on_poly == con_dot.on_poly)):
available_bool = True
return
available_bool = False
return
def fix_loop_list(loop_line_list):
to_return = []
front_con = False
back_con = False
for x in loop_line_list:
for y in loop_line_list:
if (x != y and y.line_string.intersects(Point(x.point_list[0]))):
front_con = True
if (x != y and y.line_string.intersects(Point(x.point_list[-1]))):
back_con = True
if not (front_con and back_con):
x.marked = True
front_con = False
back_con = False
for line in loop_line_list:
if not line.marked:
to_return.append(line)
for line in loop_line_list:
line.marked = False
return to_return
def area_func(poly):
return poly.area
def add_to_poly_list(loop_poly):
global poly_list
new_poly_list = []
engulfing_poly = None
poly_list.sort(reverse = True, key = area_func)
cur_section = loop_poly
for poly in poly_list:
if cur_section.contains(poly):
cur_section = cur_section.difference(poly)
for poly in poly_list:
if poly.contains(cur_section):
engulfing_poly = poly
fixed_section = poly.difference(cur_section)
for poly in poly_list:
if poly == engulfing_poly:
new_poly_list.append(fixed_section)
else:
new_poly_list.append(poly)
new_poly_list.append(cur_section)
poly_list = new_poly_list
def split_line_at_dot(line, dot):
intersect_point = Point(dot.xval, dot.yval)
for x in range(0, len(line) -1):
cur_line_segment = LineString([line[x], line[x+1]])
if cur_line_segment.distance(intersect_point) < .1:
split_index = x
break
ret_line = []
temp_line = line[:split_index]
temp_line.append((dot.xval, dot.yval))
ret_line.append(temp_line)
temp_line_2 = line[split_index + 1:]
temp_line_2.insert(0,(dot.xval, dot.yval))
ret_line.append(temp_line_2)
return ret_line
def check_loop(cur_line, end_point):
global found_loop
global last_line_in_loop
if found_loop:
return
cur_line.marked = True
if cur_line.end == end_point or cur_line.start == end_point:
last_line_in_loop = cur_line
found_loop = True
return
cur_line.find_adj()
for line in cur_line.adj_lines:
if not line.marked:
line.prev_line = cur_line
check_loop(line, end_point)
def sort_loop(loop):
cur_line = loop[-1]
start_dot = cur_line.start
to_return = []
to_return.append(cur_line)
while (cur_line.end != start_dot) or (cur_line == loop[0]):
for line in loop:
if cur_line != line and cur_line.end == line.start:
to_return.append(line)
cur_line = line
break
if cur_line != line and cur_line.end == line.end:
line.reverse()
to_return.append(line)
cur_line = line
break
return to_return
def draw_game_setup(phase_tracker):
waiting_text = None
if phase_tracker == 0:
setup_text = turn_font.render("Press Enter to start hosting a game, or press Space to connect to a host.", True, (0,0,0))
elif phase_tracker == 1:
setup_text = smaller_font.render("Connection code has been copied to clipboard. Send this code to your friend to start playing!", True, (0,0,0))
waiting_text = turn_font.render("Waiting for Player 2 to connect...", True, (0,0,0))
elif phase_tracker == 2:
setup_text = turn_font.render("Copy the host's connection code to your clipboard, then press Enter to play!", True, (0,0,0))
elif phase_tracker == 3:
setup_text = smaller_font.render("Invalid connection code. Please copy the host's connection code and try again!", True, (0,0,0))
screen.blit(setup_text, ((SCREEN_WIDTH / 2) - (setup_text.get_rect().width / 2), 20))
if waiting_text:
screen.blit(waiting_text, ((SCREEN_WIDTH / 2) - (waiting_text.get_rect().width / 2), (SCREEN_HEIGHT / 2) - (waiting_text.get_rect().height / 2)))
def draw_lines():
for line in line_list:
pygame.draw.lines(screen, "black", False, line.point_list, width = 4)
def draw_cur_line():
if(len(cur_line) > 1 ):
pygame.draw.lines(screen, "black", False, cur_line, width = 4)
def draw_dots():
for dot in dot_list:
dot.draw_self()
def draw_cur_dot():
if cur_display_dot:
pygame.draw.circle(screen, "red", (cur_display_dot.x, cur_display_dot.y), DOT_RADIUS)
def draw_intro():
if n.id == 0:
intro_text = turn_font.render("Click to place starting dots. Press enter to start!", True, (0,0,0))
else:
intro_text = turn_font.render("Waiting for player 1 to place starting dots...", True, (0,0,0))
screen.blit(intro_text, ((SCREEN_WIDTH / 2) - (intro_text.get_rect().width / 2), 20))
def draw_wins():
global wins
global win_font
p1_wins = win_font.render("Player 1 Wins: " + str(wins[0]), True, (40,40,220))
p2_wins = win_font.render("Player 2 Wins: " + str(wins[1]), True, (220,40,40))
screen.blit(p1_wins, (20, 30))
screen.blit(p2_wins, (SCREEN_WIDTH - 20 - p2_wins.get_rect().width, 30))
def draw_misc():
global turn_font
global turn_text
global n
global available_bool
if turn_text == None:
default_text = turn_font.render("Player 1's Turn", True, (0,0,0))
screen.blit(default_text,((SCREEN_WIDTH / 2) - (default_text.get_rect().width / 2), 20))
else:
screen.blit(turn_text,((SCREEN_WIDTH / 2) - (turn_text.get_rect().width / 2), 20))
if not available_bool:
if n.id == 0:
replay_text = turn_font.render("Press Enter to play again!", True, (0,0,0))
else:
replay_text = turn_font.render("Waiting for Player 1 to restart game...", True, (0,0,0))
screen.blit(replay_text, ((SCREEN_WIDTH / 2) - (replay_text.get_rect().width / 2), 80))
def setup_server_sync(received_data):
global cur_display_dot
if received_data == None or received_data == 0:
pygame.quit()
raise SystemExit
if received_data == 99:
return
if len(dot_list) == 0:
if received_data[0] != None:
new_dot = Dot(received_data[0], 0)
dot_list.append(new_dot)
elif received_data[0] != dot_list[-1].point:
new_dot = Dot(received_data[0], 0)
dot_list.append(new_dot)
if received_data[1] != cur_display_dot and received_data[1] != None:
cur_display_dot = received_data[1]
def main_server_sync(received_data):
global cur_display_dot
global cur_line
global line_list
global found_loop
if received_data == None or received_data == 0:
pygame.quit()
raise SystemExit
if received_data == 99 or (type(received_data) is list and len(received_data) < 3):
return
if received_data[1] != cur_display_dot:
cur_display_dot = received_data[1]
if received_data[2] != cur_line:
cur_line = received_data[2]
if len(line_list) == 0:
if received_data[3] != None and len(received_data[3]) > 1:
new_line = Line(received_data[3], None, None)
new_line.find_start_end()
new_line.start.num_con += 1
new_line.end.num_con += 1
line_list.append(new_line)
elif line_list[-1].point_list != received_data[3] and received_data[0] == dot_list[-1].point:
new_line = Line(received_data[3], None, None)
new_line.find_start_end()
new_line.start.num_con += 1
new_line.end.num_con += 1
line_list.append(new_line)
if received_data[0] != dot_list[-1].point:
new_dot = Dot(received_data[0], 2)
dot_list.append(new_dot)
line1 = Line(received_data[3], None, None)
line1.find_start_end()
line2 = Line(received_data[4], None, None)
line2.find_start_end()
line_list[-1] = line2
line_list.append(line1)
line_list[-1].find_adj()
if line2.start == line1.end:
found_loop = True
update_backend(line2, line1)
def local_or_online():
global local
while True:
screen.fill((230, 230, 230))
text = turn_font.render("Press Space for local play (same network or computer), or Enter for online play.", True, (0,0,0))
screen.blit(text, ((SCREEN_WIDTH / 2) - (text.get_rect().width / 2), 20))
pygame.display.flip()
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
raise SystemExit
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
local = False
return
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
return
def draw_intro():
if n.id == 0:
intro_text = turn_font.render("Click to place starting dots. Press enter to start!", True, (0,0,0))
else:
intro_text = turn_font.render("Waiting for player 1 to place starting dots...", True, (0,0,0))
screen.blit(intro_text, ((SCREEN_WIDTH / 2) - (intro_text.get_rect().width / 2), 20))
def set_up_game():
global n
phase_tracker = 0
while True:
screen.fill((230, 230, 230))
draw_game_setup(phase_tracker)
clock.tick(60)
pygame.display.flip()
if phase_tracker == 1:
p2_connected = n.send(4)
if p2_connected:
return
if phase_tracker >= 2:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
raise SystemExit
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
reversed = pygame.scrap.get("text/plain;charset=utf-8").decode()
b64_ip = reversed[::-1]
b_b64_ip = b64_ip.encode("ascii")
try:
b_external_ip = b64decode(b_b64_ip)
external_ip = b_external_ip.decode("ascii")
except:
external_ip = "BAD CODE"
n = Network(external_ip)
if n.id == -1:
phase_tracker = 3
else:
return
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
raise SystemExit
elif event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN and phase_tracker == 0:
if local == False:
ssl._create_default_https_context = ssl._create_unverified_context
r = urllib.request.urlopen('https://google.com')
external_ip = urllib.request.urlopen('https://v4.ident.me/').read().decode('utf8')
else:
external_ip = socket.gethostbyname(socket.gethostname())
b_external_ip = external_ip.encode("ascii")
b_b64_ip = b64encode(b_external_ip)
b64_ip = b_b64_ip.decode("ascii")
to_send = b64_ip[::-1]
pygame.scrap.put("text/plain;charset=utf-8", to_send.encode("utf-8"))
thread = threading.Thread(target=Server.start_server, args = ())
thread.daemon = True
thread.start()
phase_tracker = 1
local_ip = socket.gethostbyname(socket.gethostname())
n = Network(local_ip)
elif event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE and phase_tracker == 0:
phase_tracker = 2
def set_up_board():
global n
global cur_display_dot
while True:
screen.fill((230, 230, 230))
draw_cur_dot()
draw_dots()
draw_intro()
draw_wins()
clock.tick(60)
pygame.display.flip()
if n.id == 0:
if len(dot_list) == 0:
to_send_list = [None, cur_display_dot]
else:
to_send_list = [dot_list[-1].point, cur_display_dot]
n.send(to_send_list)
for event in pygame.event.get():
if event.type == pygame.QUIT:
n.send(22)
pygame.quit()
raise SystemExit
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 and cur_display_dot:
new_dot = Dot(cur_display_dot, 0)
dot_list.append(new_dot)
pass
elif event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
cur_display_dot = None
n.send(24)
return
mpos = pygame.mouse.get_pos()
mpos_point = Point(mpos)
cur_display_dot = mpos_point
for dot in dot_list:
if dot.point.distance(mpos_point) < DOT_RADIUS * 4:
cur_display_dot = None
break
else:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
raise SystemExit
received_list = n.send([True, 4])
if (received_list == 48):
break
setup_server_sync(received_list)
def update_backend(line1, line2):
global found_loop
global loop_line_list
global p1_turn
global cur_display_dot
global dot_mode
start_dot = line1.start
end_dot = line2.end
remove_line_dups()
remove_dot_dups()
line_list[-2].marked = True
if len(line_list[-1].adj_lines) > 1:
check_loop(line_list[-1], start_dot)
for line in line_list:
line.marked = False
if found_loop:
loop_line_list.clear()
if start_dot == end_dot:
loop_line_list.append(line1)
loop_line_list.append(line2)
loop_poly = Polygon(line1.point_list + line2.point_list)
else:
temp_line = last_line_in_loop
big_line = []
while temp_line.prev_line != None:
loop_line_list.append(temp_line)
temp_line = temp_line.prev_line
loop_line_list.append(line1)
loop_line_list.append(line2)
loop_line_list = fix_loop_list(loop_line_list)
sorted_loop = sort_loop(loop_line_list)
for line in sorted_loop:
big_line += line.point_list
loop_poly = Polygon(big_line)
add_to_poly_list(loop_poly)
found_loop = False
cur_display_dot = None
dot_mode = False
update_dot_boundings()
available_moves()
n.send([dot_list[-1].point, cur_display_dot, cur_line, line_list[-1].point_list, line_list[-2].point_list])
n.send(12)
p1_turn = not p1_turn
update_misc()
programIcon = pygame.image.load('miniIcon.png')
pygame.display.set_icon(programIcon)
pygame.display.set_caption("Sprouts")
local_or_online()
set_up_game()
set_up_board()
# TODO: break main loop into more readable functions
while True:
screen.fill((230, 230, 230))
draw_dots()
draw_cur_line()
draw_lines()
draw_cur_dot()
draw_misc()
draw_wins()
clock.tick(60)
pygame.display.flip()
if n.id == 0 and not available_bool:
for event in pygame.event.get():
if event.type == pygame.QUIT:
n.send(22)
pygame.quit()
raise SystemExit
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
n.send(33)
dot_list.clear()
line_list.clear()
poly_list.clear()
loop_line_list.clear()
available_bool = True
set_up_board()
p1_turn = True
update_misc()
if not n.id == p1_turn and available_bool:
cur_line = remove_consecutive_dups(cur_line)
if len(line_list) < 1:
to_send_list = [dot_list[-1].point, cur_display_dot, cur_line, None, None]
else:
to_send_list = [dot_list[-1].point, cur_display_dot, cur_line, line_list[-1].point_list, None]
n.send(to_send_list)
for event in pygame.event.get():
if event.type == pygame.QUIT:
n.send(22)
pygame.quit()
raise SystemExit
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
mpos = pygame.mouse.get_pos()
if not dot_mode:
for dot in dot_list:
if (abs(mpos[0] - dot.xval) <= DOT_RADIUS - 2) and (abs(mpos[1] - dot.yval) <= DOT_RADIUS - 2):
start_dot = dot
dragging = True
elif cur_display_dot:
new_dot = Dot(cur_display_dot, 2)
dot_list.append(new_dot)
# put inside function
two_lines = split_line_at_dot(line_list[-1].point_list, new_dot)
line1 = Line(two_lines[0], start_dot, new_dot)
line2 = Line(two_lines[1], new_dot, end_dot)
line_list[-1] = line1
line_list.append(line2)
line_list[-1].find_adj()
update_backend(line1, line2)
elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
overlap = False
if event.button == 1 and dragging:
dragging = False
for dot in dot_list:
if (abs(mpos[0] - dot.xval) <= DOT_RADIUS - 2) and (abs(mpos[1] - dot.yval) <= DOT_RADIUS - 2):
no_dups = remove_start_and_end_overlap(remove_consecutive_dups(cur_line), start_dot, dot)
if len(no_dups) < 1:
break
temp_line_string = LineString(no_dups)
no_dups.append((dot.xval, dot.yval))
no_dups.insert(0,(start_dot.xval, start_dot.yval))
real_line_string = LineString(no_dups)
for line in line_list:
if temp_line_string.intersects(line.line_string):
overlap = True
break
for other_dot in dot_list:
if other_dot != dot and other_dot != start_dot:
for point in no_dups:
if (abs(point[0] - other_dot.xval) <= DOT_RADIUS - 1 ) and ((abs(point[1] - other_dot.yval) <= DOT_RADIUS - 1)):
overlap = True
if start_dot is dot and not overlap and real_line_string.is_simple:
end_dot = dot
if start_dot.num_con < 2:
start_dot.num_con += 2
new_line = Line(no_dups, start_dot, end_dot)
line_list.append(new_line)
found_loop = True
dot_mode = True
break
elif dot.num_con < 3 and start_dot.num_con < 3 and not overlap and real_line_string.is_simple:
end_dot = dot
dot.num_con += 1
start_dot.num_con += 1
new_line = Line(no_dups, start_dot, end_dot)
line_list.append(new_line)
dot_mode = True
break
cur_line.clear()
mpos2 = pygame.mouse.get_pos()
mpos2_point = Point(mpos2)
if dragging:
cur_line.append(mpos)
mpos = mpos2
elif dot_mode:
if mpos2_point.distance(Point(start_dot.xval, start_dot.yval)) > DOT_RADIUS + 9 and mpos2_point.distance(Point(end_dot.xval, end_dot.yval)) > DOT_RADIUS + 9:
if line_list[-1].line_string.distance(mpos2_point) < 10:
cur_display_dot = nearest_points(line_list[-1].line_string, Point(mpos2[0],mpos2[1]))[0]
else:
cur_display_dot = None
else:
cur_display_dot = None
else:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
raise SystemExit
if n.id == 0 and not available_bool:
continue
received_list = n.send([True, 4])
if received_list == 33 and n.id == 1:
dot_list.clear()
line_list.clear()
poly_list.clear()
loop_line_list.clear()
available_bool = True
set_up_board()
p1_turn = True
update_misc()
else:
main_server_sync(received_list)