-
Notifications
You must be signed in to change notification settings - Fork 0
/
tableturf_leveling.html
1134 lines (1123 loc) · 76.3 KB
/
tableturf_leveling.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/4.0.0/github-markdown.min.css"
/>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release/build/styles/default.min.css"
/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex/dist/katex.min.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/markdown-it-texmath/css/texmath.min.css" />
<script type="module">
import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs"
</script>
</head>
<body class="markdown-body">
<div class="github-markdown-body" data-color-mode="auto" data-light-theme="light" data-dark-theme="dark">
<div class="github-markdown-content">
<span
id="markdown-mermaid"
aria-hidden="true"
data-dark-mode-theme="dark"
data-light-mode-theme="default"
></span>
<h1 dir="auto" id="the-art-of-efficient-grinding-in-tableturf">
The Art of Efficient Grinding in Tableturf
</h1>
<ul dir="auto">
<li dir="auto">
<ol dir="auto">
<li dir="auto"><a href="#Introduction">Introduction</a></li>
</ol>
</li>
<li dir="auto">
<ol start="2" dir="auto">
<li dir="auto"><a href="#Strategies">Strategies</a></li>
</ol>
<ul dir="auto">
<li dir="auto">2.1. <a href="#EvaluatingAStrategy">Evaluating a Strategy</a></li>
<li dir="auto">2.2. <a href="#CodeFormat">Code Format</a></li>
<li dir="auto">
2.3. <a href="#Singleplayer">Singleplayer</a>
<ul dir="auto">
<li dir="auto">2.3.1. <a href="#AutoPass">Auto Pass</a></li>
<li dir="auto">2.3.2. <a href="#CloneJelly">Clone Jelly</a></li>
</ul>
</li>
<li dir="auto">
2.4. <a href="#Multiplayer">Multiplayer</a>
<ul dir="auto">
<li dir="auto">2.4.1. <a href="#Idea">Idea</a></li>
<li dir="auto">2.4.2. <a href="#Execution">Execution</a></li>
<li dir="auto">
2.4.3. <a href="#AutomatingEverything">Automating Everything</a>
</li>
<li dir="auto">2.4.4. <a href="#ImprovingAutomation">Improving Automation</a></li>
<li dir="auto">2.4.5. <a href="#ReliableMovement">Reliable Movement</a></li>
</ul>
</li>
</ul>
</li>
<li dir="auto">
<ol start="3" dir="auto">
<li dir="auto"><a href="#Conclusion">Conclusion</a></li>
</ol>
</li>
<li dir="auto">
<ol start="4" dir="auto">
<li dir="auto"><a href="#Acknowledgment">Acknowledgment</a></li>
</ol>
</li>
</ul>
<h2 dir="auto" id="1-a-nameintroductionaintroduction">1. <a name="Introduction"></a>Introduction</h2>
<p dir="auto">
Welcome to the fascinating world of Tableturf Battle! Whether you're a seasoned player or just
stepping into this realm, leveling up is a quest we all embark upon. In this guide, I'll unveil some
of the most efficient strategies to supercharge your leveling journey. A quick note: while I delve
deep into the tactics, a basic understanding of the game's core concepts will come in handy.
</p>
<h2 dir="auto" id="2-a-namestrategiesastrategies">2. <a name="Strategies"></a>Strategies</h2>
<p dir="auto">
This section will focus on the main part of the article: How to level up fast and/or with barely any
effort. Here we have two main categories: Singleplayer (SP) and Multiplayer (MP) strategies. SP
strategies can be executed offline and alone. They are not really efficient, but reliable and easy
to automate as well. The MP strategies involve two switches that play against each other.
</p>
<h3 dir="auto" id="21-a-nameevaluatingastrategyaevaluating-a-strategy">
2.1. <a name="EvaluatingAStrategy"></a>Evaluating a Strategy
</h3>
<p dir="auto">
The metric I use to describe how good a strategy is, is "Points per Second". which means
the more points you gain in a second, the faster you will level up. For simplicity sake I will
assume that one level requires you to get 3333 EXP and that you start at level 50. Here are some key
numbers:
</p>
<table dir="auto">
<thead dir="auto">
<tr dir="auto">
<th>EXP per Second</th>
<th>EXP per Hour</th>
<th>Minutes per Level</th>
<th>Level Per 30 Days</th>
<th>Days To Level 999</th>
</tr>
</thead>
<tbody dir="auto">
<tr dir="auto">
<td>0.31</td>
<td>1111</td>
<td>180</td>
<td>240</td>
<td>119</td>
</tr>
<tr dir="auto">
<td>0.62</td>
<td>2222</td>
<td>120</td>
<td>480</td>
<td>60</td>
</tr>
<tr dir="auto">
<td>0.93</td>
<td>3333</td>
<td>60</td>
<td>720</td>
<td>40</td>
</tr>
<tr dir="auto">
<td>1</td>
<td>3600</td>
<td>56</td>
<td>777</td>
<td>37</td>
</tr>
<tr dir="auto">
<td>1.2</td>
<td>4320</td>
<td>46</td>
<td>933</td>
<td>31</td>
</tr>
<tr dir="auto">
<td>1.5</td>
<td>5400</td>
<td>37</td>
<td>1166</td>
<td>25</td>
</tr>
</tbody>
</table>
<p dir="auto">
Ideally we want to get as high as possible, but something like 1.2 EXP per Second is already enough
to get to level 999 within a month.
</p>
<h3 dir="auto" id="22-a-namecodeformatacode-format">2.2. <a name="CodeFormat"></a>Code Format</h3>
<p dir="auto">
In order to describe certain aspects that can be coded a pseudocode language similar to python is
used. Further the following assumptions are met:
</p>
<ul dir="auto">
<li dir="auto"><code>player1</code> refers to the controller of player 1.</li>
<li dir="auto"><code>player2</code> refers to the controller of player 2.</li>
<li dir="auto">
<code>current_frame</code> refers to the current frame returned by the capture device.
</li>
<li dir="auto">
<code>controller.input(buttons, delay)</code> refers to a method that inputs a list of buttons
with a delay between each of press <code>delay</code>seconds.
</li>
</ul>
<h3 dir="auto" id="23-a-namesingleplayerasingle-player">
2.3. <a name="Singleplayer"></a>Singleplayer
</h3>
<h4 dir="auto" id="231-a-nameautopassaauto-pass">2.3.1. <a name="AutoPass"></a>Auto Pass</h4>
<p dir="auto">
This is the simplest strategy. It takes quite some time to level up, but it is really reliable and
has no additional costs. For this strategy you go into a battle and simply pass every turn until you
lose. Every loss will give you 40 EXP and takes roughly 2 minutes, which means we get roughly 0.33
EXP per Second. This task can easily be automated, i.e. with a
<a href="https://github.com/Brikwerk/nxbt">Bluetooth Controller</a>. The macro here to use is
</p>
<pre><code class="code-line language-python" dir="auto"><div><span class="hljs-keyword">def</span> <span class="hljs-title function_">skip_turn</span>():
player1.<span class="hljs-built_in">input</span>([DPAD_UP, A, A, B], <span class="hljs-number">0.02</span>)
sleep(<span class="hljs-number">1</span>)
</div></code></pre>
<p dir="auto">
Repeating this sequence an infinite amount of time will let you pass every match and start a new
match.
</p>
<h4 dir="auto" id="232-a-nameclonejellyaclone-jelly">2.3.2. <a name="CloneJelly"></a>Clone Jelly</h4>
<p dir="auto">
This method requires you to be on level 47 or higher as this unlocks the NPC opponent "Clone
Jelly". This enemy has the specific trait that it copies your deck. With the correct strategy
you can get up to 0.83 Points per Second when playing against a Level 1 Clone Jelly, 0.96 Points per
Second when playing against a Level 2 Clone Jelly, or 1.08 Points per Second when playing against a
Level 3 Clone Jelly. There are two main strategies to beat Clone Jelly reliably:
</p>
<ol dir="auto">
<li dir="auto">
Low Tile Count + 3-12 Finish: The deck here is pretty simple: it consists of your 14 lowest tile
count cards and one card with a tile count of 12 and a special cost of 3. Your strategy is to
build 3 special points and use the 3-12 card on the last turn to overlap the tiles of the enemy.
</li>
<li dir="auto">
Low Tile Count: This deck consists of 3 low tile count cards and 12 cards that have a higher
tile count than the 3. As of Splatoon 3 Version 4.x the smallest possible deck that fulfils this
criteria consists of 1 card of size 1, 2 cards of size 2, 5 cards of size 3, and 7 cards of size
4. Alternative you can also use 12 cards of size 5. The strategy is to place every card except
for the low tile count ones, no specials needed. Clone Jelly Level 3 will always force a Draw
out of this, against Clone Jelly Level 2 you will have a win rate of around 66% and against
Clone Jelly Level 1 you will have a win rate of around 75% with this strategy.
</li>
</ol>
<h3 dir="auto" id="24-a-namemultiplayeramultiplayer">2.4. <a name="Multiplayer"></a>Multiplayer</h3>
<p dir="auto">
This section talks about the most efficient way of leveling. This requires additional hardware:
</p>
<ul dir="auto">
<li dir="auto">Two switch consoles</li>
<li dir="auto">A capture card</li>
<li dir="auto">Two controlling devices</li>
<li dir="auto">Two copies of the game</li>
</ul>
<p dir="auto">
I will not talk about the different possible controlling devices in detail, but my personal
suggestion is either using an emulated
<a href="https://github.com/Brikwerk/nxbt">Bluetooth Controller</a>, as this technically allows you
to control two switches with only one dongle, or using two arduino boards running a modified version
of the <a href="https://github.com/shinyquagsire23/Switch-Fightstick">Switch Fightstick PoC</a> for
optimal controller connection and speed. My personal recommendation is the
<a href="https://github.com/brianuuu/AutoController_swsh">Smart Program Controller</a> by
<a href="https://twitter.com/brianuuuSonic/">Brianuuu</a>, which also includes a manual with all
hardware and setup information you need.
</p>
<h4 dir="auto" id="241-a-nameideaaidea">2.4.1. <a name="Idea"></a>Idea</h4>
<p dir="auto">
The core idea for this farming method is that in a match against another real player, you get as
many EXP as you get points in the round. This unfortunately caps at 100 points per player, but you
still get the points no matter if you win, or lose. You also get the points when prematurely ending
the match, which allows us to reduce the time of a match to less than 90 seconds while getting a lot
of EXP.
</p>
<h4 dir="auto" id="242-a-nameexecutionaexecution">2.4.2. <a name="Execution"></a>Execution</h4>
<p dir="auto">
The most simple way to gain a lot of EXP is to use the Auto Pass strategy on one switch, and play
for as many points as possible. The deck to use here is your 15 cards with the biggest tile count.
This method gave me on average 1.3 EXP per Second. Further, it is optimal to give up the match when
you have 90 or more points, as the additional time to place another card is not efficient for the
time it takes to select and place the card.
</p>
<p dir="auto">
This method is simple and does not require much additional equipment besides a second switch and a
second game. Theoretically this method can also be executed with a friend online, with the only
problem being that you automatically disconnect after 4h in a lobby (see
<a
href="https://en-americas-support.nintendo.com/app/answers/detail/a_id/59461/~/how-to-update-splatoon-3"
>Splatoon 3 Patch Notes, Version 4.0.0</a
>
for them acknowledging the bug).
</p>
<h4 dir="auto" id="243-a-nameautomatingeverythingaautomating-everything">
2.4.3. <a name="AutomatingEverything"></a>Automating Everything
</h4>
<p dir="auto">
Ideally we want to automate this whole process for both switches. In this section I will give an
overview of various steps that are required for automating the process.
</p>
<p dir="auto">First I will define some functions that will be used in the code:</p>
<pre><code class="code-line language-python" dir="auto"><div><span class="hljs-keyword">def</span> <span class="hljs-title function_">confirm</span>(<span class="hljs-params">controller</span>):
controller.<span class="hljs-built_in">input</span>([A], <span class="hljs-number">0.02</span>)
<span class="hljs-keyword">def</span> <span class="hljs-title function_">cancel</span>(<span class="hljs-params">controller</span>):
controller.<span class="hljs-built_in">input</span>([B], <span class="hljs-number">0.02</span>)
<span class="hljs-keyword">def</span> <span class="hljs-title function_">skip_turn</span>(<span class="hljs-params">controller</span>):
controller.<span class="hljs-built_in">input</span>([DPAD_UP, A, A, B], <span class="hljs-number">0.02</span>)
sleep(<span class="hljs-number">1</span>)
</div></code></pre>
<p dir="auto">Next I want to describe a state machine that describes a game:</p>
<pre style="all: unset"><div class="mermaid">stateDiagram-v2
direction LR
state "Get Frame" as gf
state "Wait" as w
state "Deck Selection" as ds
state "Redraw" as rd
state "Stage Selection" as ss
state "Select Card" as sc
state "Place Card" as pc
state "Check End Of Turn" as ceot
state "Give Up" as gu
state Turn {
direction LR
[*] --> gf
gf --> ss
gf --> ds
gf --> rd
gf --> sc
gf --> pc
gf --> w
ss --> ceot
ds --> ceot
rd --> ceot
sc --> ceot
pc --> ceot
w --> ceot
ceot --> gf: if turn not over
ceot --> [*]: if turn over
}
[*] --> Turn
Turn --> Turn: if points < 90
Turn --> gu: if points => 90
gu --> [*]</div></pre>
<p dir="auto">
The advantages of a system like this is that it does not depend on the previous state and can
basically be started from any point of the game. Further, a new state to handle a disconnect can
also be introduced easily. I will now talk about some of the states in detail.
</p>
<p dir="auto">
The <code>Stage Selection</code> is quite easy. We can either play on the Stage
<em>Main Street</em> or on the Stage <em>Double Gemini</em> for the most reliable way to get points.
<em>Double Gemini</em> is the stage with the most tiles, so even by placing cards randomly on the
board we can assure a lot of points per game. On the other hand is Main Street the first map in the
selection screen, which makes the <code>Stage Selection</code> part trivial. The code for this state
could look like this:
</p>
<pre><code class="code-line language-python" dir="auto"><div><span class="hljs-keyword">def</span> <span class="hljs-title function_">handle_stage_selection</span>(<span class="hljs-params">frame</span>):
cursor = get_current_cursor_position(frame)
<span class="hljs-keyword">if</span> cursor != target:
move_cursor(cursor, target)
<span class="hljs-keyword">else</span>:
confirm(player1)
</div></code></pre>
<p dir="auto">
This implementation ensures that all movement input comes through before confirming it.
</p>
<p dir="auto">
The next state is the <code>Deck Selection</code>. We can use the same code base as for
<code>Stage Selection</code> here, but my suggestion is that we assume that the deck we want to use
is on the first slot for both players:
</p>
<pre><code class="code-line language-python" dir="auto"><div><span class="hljs-keyword">def</span> <span class="hljs-title function_">handle_deck_selection</span>(<span class="hljs-params">frame</span>):
confirm(player1)
confirm(player2)
</div></code></pre>
<p dir="auto">
For the <code>Redraw</code> state we have two choices: Either parse the current hand and redraw if
we only have "low cards" or just accept it and confirm as fast as possible.
</p>
<p dir="auto">
The <code>Select Card</code> state is a lot more interesting. In this state we pick a card that we
want to place on the board. The AI algorithm can be a lot of things, depending on your map. In
general it is advised to only look at <strong>unrotated</strong> cards, as rotations also rotate the
start point of the card which makes it harder to correctly calculate the sequence for the movement.
Further, it should always pick the card with the most tiles. For <em>Main Street</em> I suggest to
play the card as close to your start point as possible, while on <em>Double Gemini</em> nearly
everything will work.
</p>
<pre><code class="code-line language-python" dir="auto"><div><span class="hljs-keyword">def</span> <span class="hljs-title function_">handle_select_card</span>(<span class="hljs-params">frame</span>):
skip_turn(player2)
hand = get_hand(frame)
field = get_field(frame)
cursor = get_current_cursor_position(frame)
turn = generate_turn(hand, field)
<span class="hljs-keyword">if</span> cursor != turn.hand:
move_cursor(cursor, turn.hand)
<span class="hljs-keyword">else</span>:
confirm(player1)
<span class="hljs-keyword">return</span> turn
</div></code></pre>
<p dir="auto">
For the <code>Place Card</code> state the difference between current position and target position is
calculated and then the card is moved. This could look like this:
</p>
<pre><code class="code-line language-python" dir="auto"><div><span class="hljs-keyword">def</span> <span class="hljs-title function_">handle_place_card</span>(<span class="hljs-params">frame, turn</span>):
current = get_current_card_position(frame)
diff_x, diff_y = current - turn.target
sequence = []
<span class="hljs-keyword">if</span> diff_x > <span class="hljs-number">0</span>:
sequence.extend([DPAD_LEFT] * diff_x)
<span class="hljs-keyword">elif</span> diff_x < <span class="hljs-number">0</span>:
sequence.extend([DPAD_RIGHT] * -diff_x)
<span class="hljs-keyword">if</span> diff_y > <span class="hljs-number">0</span>:
sequence.extend([DPAD_DOWN] * diff_y)
<span class="hljs-keyword">elif</span> diff_y < <span class="hljs-number">0</span>:
sequence.extend([DPAD_UP] * -diff_y)
<span class="hljs-keyword">if</span> <span class="hljs-built_in">len</span>(sequence) == <span class="hljs-number">0</span>:
<span class="hljs-comment"># no moves to do</span>
confirm(player1)
<span class="hljs-keyword">else</span>:
<span class="hljs-comment"># move to position</span>
player1.<span class="hljs-built_in">input</span>(sequence, <span class="hljs-number">0.03</span>)
</div></code></pre>
<p dir="auto">
After placing the card we repeat the process until we detect that our points are greater than 90 OR
when no turn can be executed anymore. In that case we enter the state <code>Give Up</code>:
</p>
<pre><code class="code-line language-python" dir="auto"><div><span class="hljs-keyword">def</span> <span class="hljs-title function_">handle_give_up</span>(<span class="hljs-params">frame</span>):
cursor = get_current_cursor_position(frame)
<span class="hljs-keyword">if</span> cursor == -<span class="hljs-number">1</span>:
<span class="hljs-comment"># no give up screen up yet</span>
player1.<span class="hljs-built_in">input</span>([PLUS], <span class="hljs-number">0.02</span>)
<span class="hljs-keyword">if</span> cursor == <span class="hljs-number">0</span>:
<span class="hljs-comment"># not giving up</span>
player1.<span class="hljs-built_in">input</span>([DPAD_RIGHT], <span class="hljs-number">0.02</span>)
<span class="hljs-keyword">if</span> cursor == <span class="hljs-number">1</span>:
confirm(player1)
</div></code></pre>
<p dir="auto">
After that we can either introduce more states or start a new round and be in state
<code>Wait</code>:
</p>
<pre><code class="code-line language-python" dir="auto"><div><span class="hljs-keyword">def</span> <span class="hljs-title function_">handle_wait</span>(<span class="hljs-params">frame</span>):
confirm(player1)
confirm(player2)
</div></code></pre>
<h4 dir="auto" id="244-a-nameimprovingautomationaimproving-automation">
2.4.4. <a name="ImprovingAutomation"></a>Improving Automation
</h4>
<p dir="auto">
With a bot implemented as above we can expect roughly 0.8-0.9 EXP per Second. From my research I was
able to identify the biggest bottlenecks: The safety nets that ensure that we can execute the bot
from any given state. With a few assumptions we can improve the speed by a lot, but also make the
bot more prone to errors. First, let's take a look at the new state diagram:
</p>
<pre style="all: unset"><div class="mermaid">stateDiagram-v2
direction LR
state "Get Frame" as gf
state "Wait" as w
state "Select Card" as sc
state "Check End Of Turn" as ceot
state "Give Up" as gu
state Turn {
direction LR
[*] --> gf
gf --> sc
gf --> w
sc --> ceot
w --> ceot
ceot --> gf: if turn not over
ceot --> [*]: if turn over
}
[*] --> Turn
Turn --> Turn: if points < 90
Turn --> gu: if points => 90
gu --> [*]</div></pre>
<p dir="auto">
By removing every state except for <code>Select Card</code>, <code>Wait</code> and
<code>Give Up</code>, we assume that both players have the deck in position 1, and that we always
play on <em>Main Street</em>. Further, depending on the controller type we use, we might end up in
an endless-loop as commands might not get through. But if none of that is a problem, then we can
change the <code>Select Card</code> method to the following:
</p>
<pre><code class="code-line language-python" dir="auto"><div><span class="hljs-keyword">def</span> <span class="hljs-title function_">handle_select_card</span>(<span class="hljs-params">frame</span>):
<span class="hljs-comment"># always skip player 2</span>
skip_turn(player2)
<span class="hljs-comment"># we get the current hand and field</span>
hand = get_hand(frame)
field = get_field(frame)
<span class="hljs-comment"># cursor is always 0 in our assumption</span>
cursor = <span class="hljs-number">0</span>
<span class="hljs-comment"># we assume that we have no rotations</span>
turn = generate_turn(hand, field)
<span class="hljs-keyword">if</span> cursor != turn.hand:
<span class="hljs-comment"># move to position</span>
move_cursor(cursor, turn.hand)
<span class="hljs-comment"># assume that we are correct with out placement</span>
confirm(player1)
<span class="hljs-comment"># we calculate the starting position based on the shape of the card</span>
current = get_current_card_position(turn.card)
diff_x, diff_y = current - turn.target
sequence = []
<span class="hljs-keyword">if</span> diff_x > <span class="hljs-number">0</span>:
sequence.extend([DPAD_LEFT] * diff_x)
<span class="hljs-keyword">elif</span> diff_x < <span class="hljs-number">0</span>:
sequence.extend([DPAD_RIGHT] * -diff_x)
<span class="hljs-keyword">if</span> diff_y > <span class="hljs-number">0</span>:
sequence.extend([DPAD_DOWN] * diff_y)
<span class="hljs-keyword">elif</span> diff_y < <span class="hljs-number">0</span>:
sequence.extend([DPAD_UP] * -diff_y)
<span class="hljs-comment"># press A at the end of the sequence </span>
sequence.append(A)
player1.<span class="hljs-built_in">input</span>(sequence, <span class="hljs-number">0.03</span>)
</div></code></pre>
<p dir="auto">
The start position of a card can easily be calculated. For <em>Main Stage</em> we use the following
assumptions:
</p>
<ul dir="auto">
<li dir="auto">
The field size is
<eq
><span class="katex"
><span class="katex-mathml"
><math xmlns="http://www.w3.org/1998/Math/MathML"
><semantics
><mrow><mn>9</mn><mo>×</mo><mn>26</mn></mrow>
<annotation encoding="application/x-tex">9\times26</annotation></semantics>
</math>
></span
><span class="katex-html" aria-hidden="true"
><span class="base"
><span
class="strut"
style="height: 0.72777em; vertical-align: -0.08333em"
></span>
<span class="mord">9</span>
<span class="mspace" style="margin-right: 0.2222222222222222em"></span>
<span class="mbin">×</span>
<span class="mspace" style="margin-right: 0.2222222222222222em"></span></span>
<span class="base"></span>
<span class="strut" style="height: 0.64444em; vertical-align: 0em"></span>
<span class="mord">26</span></span>
</span>
</span>
</eq>.
</li>
<li dir="auto">
Top left is
<eq
><span class="katex"
><span class="katex-mathml"
><math xmlns="http://www.w3.org/1998/Math/MathML"
><semantics
><mrow
><mo stretchy="false">(</mo><mn>0</mn><mo separator="true">,</mo>
<mn>0</mn><mo stretchy="false">)</mo></mrow>
<annotation encoding="application/x-tex">(0, 0)</annotation></semantics>
</math>
</span
><span class="katex-html" aria-hidden="true"
><span class="base"
><span class="strut" style="height: 1em; vertical-align: -0.25em"></span
><span class="mopen">(</span><span class="mord">0</span
><span class="mpunct">,</span
><span class="mspace" style="margin-right: 0.16666666666666666em"></span
><span class="mord">0</span><span class="mclose">)</span></span
></span
></span
></eq
>.
</li>
<li dir="auto">
The opponent start position is
<eq
><span class="katex"
><span class="katex-mathml"
><math xmlns="http://www.w3.org/1998/Math/MathML"
><semantics
><mrow
><mo stretchy="false">(</mo><mn>4</mn><mo separator="true">,</mo
><mn>3</mn><mo stretchy="false">)</mo></mrow
><annotation encoding="application/x-tex">(4, 3)</annotation></semantics
></math
></span
><span class="katex-html" aria-hidden="true"
><span class="base"
><span class="strut" style="height: 1em; vertical-align: -0.25em"></span
><span class="mopen">(</span><span class="mord">4</span
><span class="mpunct">,</span
><span class="mspace" style="margin-right: 0.16666666666666666em"></span
><span class="mord">3</span><span class="mclose">)</span></span
></span
></span
></eq
>.
</li>
<li dir="auto">
Your start position is
<eq
><span class="katex"
><span class="katex-mathml"
><math xmlns="http://www.w3.org/1998/Math/MathML"
><semantics
><mrow
><mo stretchy="false">(</mo><mn>4</mn><mo separator="true">,</mo
><mn>22</mn><mo stretchy="false">)</mo></mrow
><annotation encoding="application/x-tex">(4, 22)</annotation></semantics
></math
></span
><span class="katex-html" aria-hidden="true"
><span class="base"
><span class="strut" style="height: 1em; vertical-align: -0.25em"></span
><span class="mopen">(</span><span class="mord">4</span
><span class="mpunct">,</span
><span class="mspace" style="margin-right: 0.16666666666666666em"></span
><span class="mord">22</span><span class="mclose">)</span></span
></span
></span
></eq
>.
</li>
<li dir="auto">Our card is shrunken, i.e. there is no full row or column with unset tiles only.</li>
<li dir="auto">The position of a card is given by the coordinates of its top left tile.</li>
<li dir="auto">
<eq
><span class="katex"
><span class="katex-mathml"
><math xmlns="http://www.w3.org/1998/Math/MathML"
><semantics
><mrow><mi>h</mi></mrow
><annotation encoding="application/x-tex">h</annotation></semantics
></math
></span
><span class="katex-html" aria-hidden="true"
><span class="base"
><span class="strut" style="height: 0.69444em; vertical-align: 0em"></span
><span class="mord mathnormal">h</span></span
></span
></span
></eq
>
is defined as the height of the shrunken card, and
<eq
><span class="katex"
><span class="katex-mathml"
><math xmlns="http://www.w3.org/1998/Math/MathML"
><semantics
><mrow><mi>w</mi></mrow
><annotation encoding="application/x-tex">w</annotation></semantics
></math
></span
><span class="katex-html" aria-hidden="true"
><span class="base"
><span class="strut" style="height: 0.43056em; vertical-align: 0em"></span
><span class="mord mathnormal" style="margin-right: 0.02691em">w</span></span
></span
></span
></eq
>
as the width.
</li>
<li dir="auto">
<eq
><span class="katex"
><span class="katex-mathml"
><math xmlns="http://www.w3.org/1998/Math/MathML"
><semantics
><mrow
><msub><mi>o</mi><mi>h</mi></msub
><mo lspace="0em" rspace="0em"><mi mathvariant="normal">≔</mi></mo
><mo stretchy="false" lspace="0em" rspace="0em">⌊</mo
><mfrac><mi>h</mi><mn>2</mn></mfrac
><mo stretchy="false" lspace="0em" rspace="0em">⌋</mo></mrow
><annotation encoding="application/x-tex"
>o_h{\coloneqq}{\lfloor}\frac{h}{2}{\rfloor}</annotation
></semantics
></math
></span
><span class="katex-html" aria-hidden="true"
><span class="base"
><span
class="strut"
style="height: 1.2251079999999999em; vertical-align: -0.345em"
></span
><span class="mord"
><span class="mord mathnormal">o</span
><span class="msupsub"
><span class="vlist-t vlist-t2"
><span class="vlist-r"
><span class="vlist" style="height: 0.33610799999999996em"
><span
style="
top: -2.5500000000000003em;
margin-left: 0em;
margin-right: 0.05em;
"
><span class="pstrut" style="height: 2.7em"></span
><span class="sizing reset-size6 size3 mtight"
><span class="mord mathnormal mtight">h</span></span
></span
></span
><span class="vlist-s"></span></span
><span class="vlist-r"
><span class="vlist" style="height: 0.15em"
><span></span></span></span></span></span></span
><span class="mord"
><span class="mrel"
><span class="mrel"
><span class="mop" style="position: relative; top: -0.03472em"
>:</span
></span
><span class="mrel"
><span
class="mspace"
style="margin-right: -0.06666666666666667em"
></span></span
><span class="mrel">=</span></span
></span
><span class="mord"><span class="mopen">⌊</span></span
><span class="mord"
><span class="mopen nulldelimiter"></span
><span class="mfrac"
><span class="vlist-t vlist-t2"
><span class="vlist-r"
><span class="vlist" style="height: 0.8801079999999999em"
><span style="top: -2.6550000000000002em"
><span class="pstrut" style="height: 3em"></span
><span class="sizing reset-size6 size3 mtight"
><span class="mord mtight"
><span class="mord mtight">2</span></span
></span
></span
><span style="top: -3.23em"
><span class="pstrut" style="height: 3em"></span
><span
class="frac-line"
style="border-bottom-width: 0.04em"
></span></span
><span style="top: -3.394em"
><span class="pstrut" style="height: 3em"></span
><span class="sizing reset-size6 size3 mtight"
><span class="mord mtight"
><span class="mord mathnormal mtight"
>h</span
></span
></span
></span
></span
><span class="vlist-s"></span></span
><span class="vlist-r"
><span class="vlist" style="height: 0.345em"
><span></span></span></span></span></span
><span class="mclose nulldelimiter"></span></span
><span class="mord"><span class="mclose">⌋</span></span></span
></span
></span
></eq
>
</li>
<li dir="auto">
<eq
><span class="katex"
><span class="katex-mathml"
><math xmlns="http://www.w3.org/1998/Math/MathML"
><semantics
><mrow
><msub><mi>o</mi><mi>w</mi></msub
><mo lspace="0em" rspace="0em"><mi mathvariant="normal">≔</mi></mo
><mo stretchy="false" lspace="0em" rspace="0em">⌊</mo
><mfrac
><mrow><mi>w</mi><mo>−</mo><mn>1</mn></mrow
><mn>2</mn></mfrac
><mo stretchy="false" lspace="0em" rspace="0em">⌋</mo></mrow
><annotation encoding="application/x-tex"
>o_w{\coloneqq}{\lfloor}\frac{w-1}{2}{\rfloor}</annotation
></semantics
></math
></span
><span class="katex-html" aria-hidden="true"
><span class="base"
><span class="strut" style="height: 1.190108em; vertical-align: -0.345em"></span
><span class="mord"
><span class="mord mathnormal">o</span
><span class="msupsub"
><span class="vlist-t vlist-t2"
><span class="vlist-r"
><span class="vlist" style="height: 0.151392em"
><span
style="
top: -2.5500000000000003em;
margin-left: 0em;
margin-right: 0.05em;
"
><span class="pstrut" style="height: 2.7em"></span
><span class="sizing reset-size6 size3 mtight"
><span
class="mord mathnormal mtight"
style="margin-right: 0.02691em"
>w</span
></span
></span
></span
><span class="vlist-s"></span></span
><span class="vlist-r"
><span class="vlist" style="height: 0.15em"
><span></span></span></span></span></span></span
><span class="mord"
><span class="mrel"
><span class="mrel"
><span class="mop" style="position: relative; top: -0.03472em"
>:</span
></span
><span class="mrel"
><span
class="mspace"
style="margin-right: -0.06666666666666667em"
></span></span
><span class="mrel">=</span></span
></span
><span class="mord"><span class="mopen">⌊</span></span
><span class="mord"
><span class="mopen nulldelimiter"></span
><span class="mfrac"
><span class="vlist-t vlist-t2"
><span class="vlist-r"
><span class="vlist" style="height: 0.845108em"
><span style="top: -2.6550000000000002em"
><span class="pstrut" style="height: 3em"></span
><span class="sizing reset-size6 size3 mtight"
><span class="mord mtight"
><span class="mord mtight">2</span></span
></span
></span
><span style="top: -3.23em"
><span class="pstrut" style="height: 3em"></span
><span
class="frac-line"
style="border-bottom-width: 0.04em"
></span></span
><span style="top: -3.394em"
><span class="pstrut" style="height: 3em"></span
><span class="sizing reset-size6 size3 mtight"
><span class="mord mtight"
><span
class="mord mathnormal mtight"
style="margin-right: 0.02691em"
>w</span
><span class="mbin mtight">−</span
><span class="mord mtight">1</span></span
></span
></span
></span
><span class="vlist-s"></span></span
><span class="vlist-r"
><span class="vlist" style="height: 0.345em"
><span></span></span></span></span></span
><span class="mclose nulldelimiter"></span></span
><span class="mord"><span class="mclose">⌋</span></span></span
></span
></span
></eq
>
</li>
<li dir="auto">
<eq
><span class="katex"
><span class="katex-mathml"
><math xmlns="http://www.w3.org/1998/Math/MathML"
><semantics
><mrow
><msub><mi>t</mi><mi>h</mi></msub
><mo lspace="0em" rspace="0em"><mi mathvariant="normal">≔</mi></mo
><mn>22</mn><mo>−</mo><msub><mi>o</mi><mi>h</mi></msub></mrow
><annotation encoding="application/x-tex"
>t_h{\coloneqq}22 - o_h</annotation
></semantics
></math
></span
><span class="katex-html" aria-hidden="true"
><span class="base"
><span class="strut" style="height: 0.79444em; vertical-align: -0.15em"></span
><span class="mord"
><span class="mord mathnormal">t</span
><span class="msupsub"
><span class="vlist-t vlist-t2"
><span class="vlist-r"
><span class="vlist" style="height: 0.33610799999999996em"
><span
style="
top: -2.5500000000000003em;
margin-left: 0em;
margin-right: 0.05em;
"
><span class="pstrut" style="height: 2.7em"></span
><span class="sizing reset-size6 size3 mtight"
><span class="mord mathnormal mtight">h</span></span
></span
></span
><span class="vlist-s"></span></span
><span class="vlist-r"
><span class="vlist" style="height: 0.15em"
><span></span></span></span></span></span></span
><span class="mord"
><span class="mrel"
><span class="mrel"
><span class="mop" style="position: relative; top: -0.03472em"
>:</span
></span
><span class="mrel"
><span
class="mspace"
style="margin-right: -0.06666666666666667em"
></span></span
><span class="mrel">=</span></span
></span
><span class="mord">22</span
><span class="mspace" style="margin-right: 0.2222222222222222em"></span
><span class="mbin">−</span
><span class="mspace" style="margin-right: 0.2222222222222222em"></span></span
><span class="base"
><span class="strut" style="height: 0.58056em; vertical-align: -0.15em"></span
><span class="mord"
><span class="mord mathnormal">o</span
><span class="msupsub"
><span class="vlist-t vlist-t2"
><span class="vlist-r"
><span class="vlist" style="height: 0.33610799999999996em"
><span
style="
top: -2.5500000000000003em;
margin-left: 0em;
margin-right: 0.05em;
"
><span class="pstrut" style="height: 2.7em"></span
><span class="sizing reset-size6 size3 mtight"
><span class="mord mathnormal mtight">h</span></span
></span
></span
><span class="vlist-s"></span></span
><span class="vlist-r"
><span class="vlist" style="height: 0.15em"
><span></span></span></span></span></span></span></span></span></span
></eq>
</li>
<li dir="auto">
<eq
><span class="katex"
><span class="katex-mathml"
><math xmlns="http://www.w3.org/1998/Math/MathML"
><semantics
><mrow
><msub><mi>t</mi><mi>w</mi></msub
><mo lspace="0em" rspace="0em"><mi mathvariant="normal">≔</mi></mo
><mn>4</mn><mo>−</mo><msub><mi>o</mi><mi>w</mi></msub></mrow
><annotation encoding="application/x-tex"
>t_w{\coloneqq}4 - o_w</annotation
></semantics
></math
></span
><span class="katex-html" aria-hidden="true"
><span class="base"
><span class="strut" style="height: 0.79444em; vertical-align: -0.15em"></span
><span class="mord"
><span class="mord mathnormal">t</span
><span class="msupsub"
><span class="vlist-t vlist-t2"
><span class="vlist-r"
><span class="vlist" style="height: 0.151392em"
><span
style="
top: -2.5500000000000003em;
margin-left: 0em;
margin-right: 0.05em;
"
><span class="pstrut" style="height: 2.7em"></span
><span class="sizing reset-size6 size3 mtight"
><span
class="mord mathnormal mtight"
style="margin-right: 0.02691em"
>w</span
></span
></span
></span
><span class="vlist-s"></span></span
><span class="vlist-r"
><span class="vlist" style="height: 0.15em"
><span></span></span></span></span></span></span
><span class="mord"
><span class="mrel"
><span class="mrel"
><span class="mop" style="position: relative; top: -0.03472em"
>:</span
></span
><span class="mrel"
><span
class="mspace"
style="margin-right: -0.06666666666666667em"
></span></span
><span class="mrel">=</span></span
></span
><span class="mord">4</span
><span class="mspace" style="margin-right: 0.2222222222222222em"></span
><span class="mbin">−</span
><span class="mspace" style="margin-right: 0.2222222222222222em"></span></span
><span class="base"
><span class="strut" style="height: 0.58056em; vertical-align: -0.15em"></span
><span class="mord"
><span class="mord mathnormal">o</span
><span class="msupsub"
><span class="vlist-t vlist-t2"
><span class="vlist-r"
><span class="vlist" style="height: 0.151392em"
><span
style="
top: -2.5500000000000003em;
margin-left: 0em;
margin-right: 0.05em;
"