-
Notifications
You must be signed in to change notification settings - Fork 1
/
WordSearchByKAREL.py
1651 lines (1351 loc) · 38.5 KB
/
WordSearchByKAREL.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
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from gtts import gTTS
from playsound import playsound
from karel.stanfordkarel import *
"""
File: WordSearchByKAREL.py
--------------------
The overall aim of this program is for Karel to create a word
search with a high degree of randomness and then have him find
the hidden words. In this version which is appended due to
humanistic limitations, Karel knows four words; KAREL, PYTHON,
CHOCO and SHREYASI (That's me :D). Once the human user is given
a chance to try and solve the puzzle, Karel will search out all
the words he knows. Overall I found this task especially
challenging due to the high degree of forethought and perspective
of the whole map which is required in creating a word search.
Watch Karel create and solve his own word search!
****To Hide The Words*****
One of the most interesting parts about creating an algorithm
for this word search was learning how non-systematic word
searches actually are. When creating a word search there is no
simple equation that can be applied. While they can be placed
completely randomly one at a time, one of the short failings of
this method is that it could allow for the creation of a game
where there is no space to possibly fit the last few words
(especially on a 10 by 8 map). To overcome this problem I
taught Karel a way of hiding the words which combines
strategic placing and still maintains a good degree of randomness.
Of course this is also helped by the fact that four
words are not too many to hide :).
First Karel hides the word SHREYASI. He places it upright and
randomly chooses a column to put it in. However, because of
the length of this words I made him strongly favor the sides
of the game as this caused less disruption in the placing of
the other words.
To place CHOCO, Karel randomly chooses a row, checks where
SHREYASI is placed and with his remaining options randomly
selects a location
To place PYTHON and KAREL, which I made bounded together (this
decision was made not because placing them randomly separately
was impossible, but simply because the code was becoming
outrageously long and without variables etc, it would not have
been worth the effort), Karel will randomly choose any spot on
the board (minus spots which are too close to the edge for the
bounded words to fit) then check if there are any letters
already in the way. If there are words in the way it will just
look again (with the algorithm created I can be %100 sure
there will be space for the PYTHON KAREL hybrid). If it finds
an empty spot it writes in the words.
The algorithm for finding if the area where Karel is going to
write the KAREL PYTHON hybrid was very interesting to create.
If I were to make the word search completely random this is
exactly the algorithm I would use, however I figured If I did
it once, I could demonstrate I had the ability without
coding myself to death :). To check for emptiness I introduced
what I called the error beeper. If Karel ever came across a
letter in its path it would place an error beeper at the letter
it stood (one beeper above the identification beeper). The
continuation of the search is all dependent on the absence
of this error beeper and if the search ended with an error beeper
in existence it would look for a brand new location for the words
while remembering to put the error beeper away first of course :).
Though this process may seem simple, keeping the error beepers
in place without Karel confusing an error beeper with the
identification beeper of a letter was harder than it seemed
especially due to Karel's lack of coordinates. Its also important
to note that while Karel places PYTHON and KAREL together he is
oblivious to this fact and will search for both words
independently.
****
****To Find The Words****
As you may notice, in the bottom left hand side of each letter
is a pile of beepers. Seeing as Karel, until this moment was
illiterate, this is how he identified letters. Each letter
has a number equivalent which is represented by the stack.
However, while this may seem simple, reading and remembering
what he reads are more challenging. To check if a letter is the
one Karel is looking for, he will place the beepers temporarily
to the side. If he is looking for a letter with 8 beepers he
will repeat the step remove beeper if it exists 7 times. Then if
there are no more beepers he knows there were 7 or less beepers
and this is not his letter. If there are still beepers he will
move one more beeper over. If at this point there are no more
beepers he knows that before there were exactly 8 beepers on the
spot and this is the word he was looking for. Being the well
trained robot he is, Karel will always return the beepers from
where he got them.
The actual searching for specific words was by far the most code
consuming function. This is because it required large amounts of
deeply nested codes and while much of the code was similar it could
not be simplified because of the restrictions placed on this
assignment.
To make life easier I made each word have a designated direction.
In my mind I can clearly visualize how I would confront the
problem of not knowing the direction before hand but if I had
done this the already long codes for searching for words would
have been increased exponentially not to mention the added
dilemma of how to be sure these new words would all fit into
the map. I approximated the added code would be about 7x the
current code which due to the unfortunate demands of my other
classes was not my best option.
Once Karel was sufficiently convinced he had found the word he
made an attempt to circle it. Due to the very large nature of
the pixels and my lack of intrinsic aesthetic skills, the circling
doesnt always look as professional as I would like it to.
****
****How To Run****
To run word search Karel you MUST run it on a 54x61 blank world.
There are two ways of running Word Search Karel; the fast way
and the slow way.
In the slow way you can see Karel's general movements and from
this get an insight into the algorithms which occur behind the
scenes in creating this puzzle.
In the fast version, it is supposed to simulate an actual word
search game. It will draw the puzzle in what seems to be an
instant, give the viewer some time to try and solve the problem
and then show the solution. I also added in a real silly intro
and end screen shot which makes me smile :). To run this, note
out the section in run titled "slow run" and run Karel at
full speed
****Final Note****
A final note on style. In this program I tried my best to keep
a readable code which was efficient and well programmed.
However due to the long nature of a complicated program in
Karel and the absolute necessity of deeply embedded clauses
it was not always as stylistic as I would have liked it to be.
Moreover, a comment on these notes is that they only cover the
broader algorithms which dealt with the bigger issues that I
faced. There are numerous difficulties which were overcome that
had a more minor role in the overall function of the puzzle.
(such as how to circle SHREYASI with a rectangle of the same
width considering its different locations in the game)
**************************************************************
"""
# import the random library
import random
NUM_LETTERS = 21 # this denotes the number of alphabets that we will use
def main():
"""
Creates a puzzle and solves it.
Assumes that Karel starts in the bottom left of a large, empty world.
There are four basic steps to it
1. Display the Introduction message
2. Creates the puzzle
3. Solves the puzzle
4. Displays the end message
"""
text_val_1 = "Welcome to the World of KAREL. Here, KAREL is going to perform Word Search. There are four words " \
"hidden in a grid consisting of random alphabets. Dive right in to check if our little KAREL can do it"
# Here are converting in English Language
language = 'en-us'
# Passing the text and language to the engine,
# here we have assign slow=False. Which denotes
# the module that the transformed audio should
# have a high speed
obj = gTTS(text=text_val_1, lang=language, slow=False)
# Here we are saving the transformed audio in a mp3 file named
# KAREL1.mp3
obj.save("KAREL1.mp3")
# Play the KAREL1.mp3 file
playsound("KAREL1.mp3")
display_intro_message()
create_puzzle()
text_val_2 = "Ooo! That's a lot of letters... WELL, Let's hope for the best, KAREL! you can do it !"
# Here are converting in English Language
language = 'en-us'
# Passing the text and language to the engine,
# here we have assign slow=False. Which denotes
# the module that the transformed audio should
# have a high speed
obj = gTTS(text=text_val_2, lang=language, slow=False)
# Here we are saving the transformed audio in a mp3 file named
# KAREL2.mp3
obj.save("KAREL2.mp3")
# Play the KAREL2.mp3 file
playsound("KAREL2.mp3")
delay()
solve_puzzle()
display_end_message()
text_val_3 = "Finally KAREL solved the puzzle . Hope you guys liked it . Thank you!"
# Here are converting in English Language
language = 'en-us'
# Passing the text and language to the engine,
# here we have assign slow=False. Which denotes
# the module that the transformed audio should
# have a high speed
obj = gTTS(text=text_val_3, lang=language, slow=False)
# Here we are saving the transformed audio in a mp3 file named
# KAREL3.mp3
obj.save("KAREL3.mp3")
# Play the KAREL3.mp3 file
playsound("KAREL3.mp3")
def display_end_message():
"""
Displays the end message for the user....
" Thank You "
At first KAREL clears the canvas though XD
"""
reach_starting_point()
clear_canvas()
reach_starting_point()
for i in range(3):
move_up()
for i in range(2):
move_to_next_letter()
write_YOU()
for i in range(3):
move_to_next_letter()
move_up()
move_to_next_letter()
write_THANK()
reach_starting_point()
delay()
def write_YOU():
draw_Y()
move_to_next_letter()
draw_O()
move_to_next_letter()
draw_U()
move_to_next_letter()
draw_dots()
def write_THANK():
draw_T()
move_to_next_letter()
draw_H()
move_to_next_letter()
draw_A()
move_to_next_letter()
draw_N()
move_to_next_letter()
draw_K()
move_to_next_letter()
draw_dots()
def solve_puzzle():
"""
Solves the puzzle by finding the four words and creating a boundary line around them
"""
move_up()
create_boundary(8, 'row')
move_to_next_letter()
move_up()
create_boundary(6, 'column')
for i in range(2):
move_up()
move_to_next_letter()
create_boundary(5, 'row')
for i in range(5):
move_to_next_letter()
move_down()
create_boundary(5, 'column')
reach_starting_point()
def create_boundary(n, direction):
"""
This function takes two inputs
n := number of alphabets present in the word
direction := either along row or column
"""
if right_is_clear():
turn_right()
for i in range(2):
move()
if right_is_clear():
turn_right()
for i in range(2):
move()
turn_around()
else:
turn_left()
if direction == 'row':
if n == 8:
for i in range(53):
paint_corner(BLACK)
move()
paint_corner(BLACK)
turn_around()
move_to_wall()
turn_right()
for i in range(8):
move()
turn_right()
for i in range(53):
paint_corner(BLACK)
move()
paint_corner(BLACK)
turn_around()
move_to_wall()
turn_left()
for i in range(6):
move()
turn_left()
if n == 5:
for i in range(35):
move()
paint_corner(BLACK)
turn_left()
for i in range(8):
paint_corner(BLACK)
move()
turn_left()
while corner_color_is(BLANK):
paint_corner(BLACK)
move()
turn_left()
for i in range(6):
move()
turn_left()
for i in range(2):
move()
if direction == 'column':
turn_left()
if n == 6:
while front_is_clear():
paint_corner(BLACK)
move()
paint_corner(BLACK)
turn_right()
for i in range(7):
move()
turn_right()
while corner_color_is(BLANK):
paint_corner(BLACK)
move()
turn_around()
for i in range(2):
move()
turn_left()
for i in range(5):
move()
turn_around()
if n == 5:
while front_is_clear():
paint_corner(BLACK)
move()
paint_corner(BLACK)
turn_around()
while corner_color_is(BLACK):
move()
turn_around()
move()
turn_right()
for i in range(6):
move()
paint_corner(BLACK)
def create_puzzle():
"""
Creates the puzzle in a number of steps, basically
1. At first, KAREL places the four words "SHREYASI", "CHOCO", "PYTHON", "KAREL"
2. Fills up the rest of the world with random letters
"""
move_up()
write_SHREYASI()
for i in range(2):
move_up()
for i in range(2):
move_to_next_letter()
write_KAREL()
move_down()
write_CHOCO()
reach_starting_point()
move_to_next_letter()
move_up()
move_up()
write_PYTHON()
reach_starting_point()
fill_blank_spaces() # KAREL fills the empty slots now with random letters
reach_starting_point()
def move_down():
"""
This function is used by KAREL to move down to the next spot for writing a letter along a column
"""
turn_right()
for i in range(8):
move()
turn_left()
def write_CHOCO():
"""
KAREL writes the word "CHOCO" which is one of the four words in the puzzle
It writes one alphabet at a time and moves up by one slot
"""
draw_C()
move_up()
draw_H()
move_up()
draw_O()
move_up()
draw_C()
move_up()
draw_O()
def write_PYTHON():
"""
KAREL writes the word "PYTHON" which is one of the four words in the puzzle
It writes one alphabet at a time and moves up by one slot
"""
draw_N()
move_up()
draw_O()
move_up()
draw_H()
move_up()
draw_T()
move_up()
draw_Y()
move_up()
draw_P()
def fill_blank_spaces():
"""
This function helps KAREL to randomly fill in the empty slots
and completes the puzzle
"""
for i in range(40):
move_till_no_letters_present()
randomly_draw_letters()
def display_intro_message():
"""
Displays the Introduction message
" WELCOME TO WORD SEARCH WITH KAREL "
--- BY SHREYASI
"""
write_SHREYASI()
for i in range(6):
move_to_next_letter()
write_BY()
move_up()
move_to_next_letter()
write_SEARCH()
for i in range(3):
move_to_next_letter()
write_WORD()
for i in range(3):
move_to_next_letter()
write_KAREL()
draw_dots()
for i in range(5):
move_to_next_letter()
write_TO()
for i in range(3):
move_to_next_letter()
write_WELCOME()
delay()
clear_canvas() # Clears the Canvas after displaying the Introductory message to create the puzzle
reach_starting_point() # Reaches the starting point to start creating puzzle
delay() # Delays the process so that there is a gap between the four basic processes
def write_SHREYASI():
"""
Writes the word "SHREYASI" as a part of the Introductory message
This function will also be used while creating the puzzle
Places the word "SHREYASI" along a row
Draws a single letter at a time, then moves to the next spot to write the next letter...
"""
draw_S()
move_to_next_letter()
draw_H()
move_to_next_letter()
draw_R()
move_to_next_letter()
draw_E()
move_to_next_letter()
draw_Y()
move_to_next_letter()
draw_A()
move_to_next_letter()
draw_S()
move_to_next_letter()
draw_I()
move_to_next_letter()
def write_BY():
"""
Writes the word "BY" as a part of the Introductory message
Draws a single letter at a time, then moves to the next spot to write the next letter...
"""
draw_B()
move_to_next_letter()
draw_Y()
move_to_next_letter()
def delay():
"""
This function is basically meant to delay the timing between the four basic processes in main() function
"""
for i in range(5000):
turn_left()
def move_up():
"""
This function is used by KAREL to move up to the next spot for writing a letter along a column
"""
turn_left()
for i in range(8):
move()
turn_right()
def write_SEARCH():
"""
Writes the word "SEARCH" as a part of the Introductory message
Draws a single letter at a time, then moves to the next spot to write the next letter...
"""
draw_S()
move_to_next_letter()
draw_E()
move_to_next_letter()
draw_A()
move_to_next_letter()
draw_R()
move_to_next_letter()
draw_C()
move_to_next_letter()
draw_H()
move_to_next_letter()
def write_WORD():
"""
Writes the word "WORD" as a part of the Introductory message
Draws a single letter at a time, then moves to the next spot to write the next letter...
"""
draw_W()
move_to_next_letter()
draw_O()
move_to_next_letter()
draw_R()
move_to_next_letter()
draw_D()
move_to_next_letter()
def write_TO():
"""
Writes the word "TO" as a part of the Introductory message
Draws a single letter at a time, then moves to the next spot to write the next letter...
"""
draw_T()
move_to_next_letter()
draw_O()
move_to_next_letter()
def write_KAREL():
"""
Writes the word "KAREL" as a part of the Introductory message
This function will also be used while creating the puzzle
Places the word "KAREL" along a row
Draws a single letter at a time, then moves to the next spot to write the next letter...
"""
draw_K()
move_to_next_letter()
draw_A()
move_to_next_letter()
draw_R()
move_to_next_letter()
draw_E()
move_to_next_letter()
draw_L()
move_to_next_letter()
def write_WELCOME():
"""
Writes the word "WELCOME" as a part of the Introductory message
Draws a single letter at a time, then moves to the next spot to write the next letter...
"""
draw_W()
move_to_next_letter()
draw_E()
move_to_next_letter()
draw_L()
move_to_next_letter()
draw_C()
move_to_next_letter()
draw_O()
move_to_next_letter()
draw_M()
move_to_next_letter()
draw_E()
move_to_next_letter()
draw_dots()
def reach_starting_point():
"""
Reaches the starting point i.e. the 1st row and 1st column of KAREL's world
"""
move_to_wall()
turn_right()
move_to_wall()
turn_right()
move_to_wall()
turn_around()
def clear_one_row():
"""
KAREL clears one row at a time. It basically has to perform two functions:
1. Clear the colors present in the corners
2. Pick beepers if present
"""
while front_is_clear():
paint_corner(BLANK)
while beepers_present():
pick_beeper()
move()
paint_corner(BLANK)
def reach_first_column():
"""
KAREL reaches the first column
"""
turn_around()
move_to_wall()
turn_right()
move()
turn_right()
def clear_canvas():
reach_starting_point()
while left_is_clear():
clear_one_row()
reach_first_column()
clear_one_row()
def randomly_draw_letters():
"""
KAREL uses this function to randomly draw any alphabet
It makes use of the random module to perform it
"""
flag = random.randint(0, NUM_LETTERS - 1)
# the flag variable is like an indicator storing the number of the letter to store
if flag == 0:
draw_A()
elif flag == 1:
draw_B()
elif flag == 2:
draw_C()
elif flag == 3:
draw_D()
elif flag == 4:
draw_E()
elif flag == 5:
draw_F()
elif flag == 6:
draw_H()
elif flag == 7:
draw_I()
elif flag == 8:
draw_J()
elif flag == 9:
draw_K()
elif flag == 10:
draw_L()
elif flag == 11:
draw_M()
elif flag == 12:
draw_N()
elif flag == 13:
draw_O()
elif flag == 14:
draw_P()
elif flag == 15:
draw_R()
elif flag == 16:
draw_S()
elif flag == 17:
draw_T()
elif flag == 18:
draw_U()
elif flag == 19:
draw_W()
else:
draw_Y()
def draw_dots():
"""
KAREL draws three dots "..." to enhance the beauty of a word in few cases
"""
for i in range(2):
paint_corner(PINK)
move()
move()
paint_corner(PINK)
turn_around()
for i in range(4):
move()
turn_around()
def draw_A():
"""
KAREL draws letter 'A' in blue color and represents it by putting one beeper at the starting position
It's easier for KAREL to draw it row-by-row XD
"""
put_beeper()
paint_bottom_of_A()
for i in range(4):
paint_corner(BLUE)
move()
move_to_next_row()
paint_head_of_A()
move_back_to_beeper()
def paint_bottom_of_A():
# KAREL paints the bottom of letter 'A'
paint_row_of_A()
move_to_next_row()
paint_row_of_A()
move_to_next_row()
def paint_row_of_A():
# KAREL will paint a row of letter 'A' which repeats itself
# This is done in order to write the same code again for rows which have the same function
paint_corner(BLUE)
for i in range(3):
move()
paint_corner(BLUE)
move()
def paint_head_of_A():
# KAREL will paint the head or the upper portion of letter 'A'
paint_row_of_A()
move_to_next_row()
move()
for i in range(2):
paint_corner(BLUE)
move()
move()
def draw_B():
"""
KAREL draws letter 'B' in black color and represents it by putting two beepers at the starting position
It's easier for KAREL to draw it row-by-row XD
"""
for i in range(2):
put_beeper()
paint_part1_of_B()
move_to_next_row()
paint_row_of_B()
move_to_next_row()
paint_part2_of_B()
move_back_to_beeper()
def paint_part1_of_B():
# KAREL paints the part of letter 'B' which is repeated twice
paint_row_of_B()
move_to_next_row()
paint_corner(BLACK)
for i in range(3):
move()
paint_corner(BLACK)
move()
def paint_part2_of_B():
paint_corner(BLACK)
for i in range(3):
move()
paint_corner(BLACK)
move()
move_to_next_row()
paint_row_of_B()
def paint_row_of_B():
# KAREL will paint a row of letter 'B' which repeats itself
# This is done in order to write the same code again for rows which have the same function
for i in range(3):
paint_corner(BLACK)
move()
move()
def draw_C():
"""
KAREL draws letter 'C' in cyan color and represents it by putting 3 beepers at the starting position
It's easier for KAREL to draw it row-by-row XD
"""
for i in range(3):
put_beeper()
paint_part1_of_C()
paint_row3_of_C()
move_to_next_row()
paint_part2_of_C()
move_back_to_beeper()
def paint_part1_of_C():
# KAREL paints the part of letter 'C' which is repeated
paint_row1_of_C()
move_to_next_row()
paint_row2_of_C()
move_to_next_row()
def paint_part2_of_C():
paint_row2_of_C()
move_to_next_row()
paint_row1_of_C()
def paint_row1_of_C():
move()
for i in range(2):
paint_corner(CYAN)
move()
move()
def paint_row2_of_C():
paint_corner(CYAN)
for i in range(3):
move()
paint_corner(CYAN)
move()
def paint_row3_of_C():
paint_corner(CYAN)
for i in range(4):
move()
def draw_D():
"""
KAREL draws letter 'D' in dark grey color and represents it by putting 4 beepers at the starting position
It's easier for KAREL to draw it row-by-row XD
"""
for i in range(4):
put_beeper()
paint_row1_of_D()
for i in range(3):
move_to_next_row()
paint_row2_of_D()
move_to_next_row()
paint_row1_of_D()
move_back_to_beeper()
def paint_row1_of_D():
for i in range(3):
paint_corner(DARK_GRAY)
move()
move()
def paint_row2_of_D():
paint_corner(DARK_GRAY)
for i in range(3):
move()
paint_corner(DARK_GRAY)
move()
def draw_E():
"""
KAREL draws letter 'E' in gray color and represents it by putting 5 beepers at the starting position
It's easier for KAREL to draw it row-by-row XD
"""
for i in range(5):
put_beeper()
paint_row1_of_E()
move_to_next_row()
paint_row2_of_E()
move_to_next_row()
paint_row3_of_E()
move_to_next_row()
paint_row2_of_E()
move_to_next_row()
paint_row1_of_E()
move_back_to_beeper()
def paint_row1_of_E():
for i in range(4):
paint_corner(GRAY)
move()
def paint_row2_of_E():
paint_corner(GRAY)
for i in range(4):
move()
def paint_row3_of_E():
for i in range(3):
paint_corner(GRAY)
move()
move()