Skip to content

Commit 23910be

Browse files
committed
auto can
1 parent 7ce5417 commit 23910be

File tree

3 files changed

+68
-6
lines changed

3 files changed

+68
-6
lines changed

src/solitaire.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import { RNG, random, int_random, v_random, v_random_h, v_screen, arr_random } f
2424
import { Tween } from './tween'
2525
import { Button } from './ui'
2626
import { Card } from './showcase'
27-
import { SolitaireGame, card_sort_key } from './solitaire_game'
27+
import { SolitaireGame } from './solitaire_game'
2828
import { make_solitaire_back } from './solitaire_back'
29-
import { Settings } from 'lsolitaire'
29+
import { card_sort_key, Settings } from 'lsolitaire'
3030
import { Nine } from './nine'
3131

3232
let rnd_screen_poss = [...Array(50).keys()].map(() => v_random().mul(v_screen.scale(0.8)))

src/solitaire_back.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SolitaireGame } from './solitaire_game'
2-
import { Settings, Cards, Solitaire, SolitairePov, Game as OSolitaireGame, GamePov, IMoveType, TableuToTableu } from 'lsolitaire'
2+
import { Settings, Cards, Solitaire, SolitairePov, Game as OSolitaireGame, GamePov, IMoveType, TableuToTableu, IMove, TableuToFoundation, WasteToFoundation } from 'lsolitaire'
33
import { SolitaireStore } from './store'
44
import { arr_random } from './util'
55

src/solitaire_game.ts

+65-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Sound from './sound'
2-
import { Rect, Vec2 } from 'blah'
2+
import { Rect, Time, Vec2 } from 'blah'
33
import { Play } from './play'
44
import { Anim } from './anim'
55
import { Clickable } from './game'
@@ -15,6 +15,8 @@ import { HitStock, Recycle,
1515
FoundationToTableu,
1616
} from 'lsolitaire'
1717
import { SolitaireStore } from './store'
18+
import { ticks } from './shared'
19+
import { appr } from './lerp'
1820

1921
export type TableuDrag = {
2022
tableu: number,
@@ -344,6 +346,9 @@ export class SolitaireGame extends Play {
344346
return this.back_res.cmd
345347
}
346348

349+
350+
trigger_auto: number = -2
351+
347352
_init() {
348353

349354

@@ -380,6 +385,20 @@ export class SolitaireGame extends Play {
380385

381386
this.stock = this.make(Stock, Vec2.make(stock_x, stock_y), {
382387
on_waste_click() {
388+
389+
if (self.click_source === 'waste') {
390+
self._release_cancel_highlight()
391+
let hint_data = WasteToFoundation.auto_can(self.pov)
392+
if (hint_data) {
393+
self.trigger_auto = -1
394+
self.cmd(WasteToFoundation, hint_data)
395+
}
396+
397+
return
398+
}
399+
400+
401+
383402
self._release_cancel_highlight()
384403
self.stock.waste.top_card.set_highlight(true)
385404
self.click_source = 'waste'
@@ -430,6 +449,19 @@ export class SolitaireGame extends Play {
430449
let { tableu, i: _i } = self.click_source
431450

432451
if (tableu === i) {
452+
453+
if (e === 1) {
454+
self._release_cancel_highlight()
455+
let hint_data = TableuToFoundation.auto_can(self.pov, {tableu})
456+
if (hint_data) {
457+
self.trigger_auto = -1
458+
self.cmd(TableuToFoundation, hint_data)
459+
}
460+
461+
return
462+
}
463+
464+
433465
self._release_cancel_highlight()
434466
self.tableus[i].fronts.set_highlight(e, true)
435467
self.click_source = { tableu: i, i: e}
@@ -830,6 +862,13 @@ export class SolitaireGame extends Play {
830862
this.cards.shadow_group = undefined
831863
})
832864
}
865+
866+
if (res instanceof TableuToFoundation || res instanceof WasteToFoundation) {
867+
if (this.trigger_auto === -3) {
868+
this.trigger_auto = -1
869+
}
870+
}
871+
833872
}
834873

835874
apply_pov(cmd: IMoveType<SolitairePov, Solitaire>, data: any) {
@@ -865,6 +904,29 @@ export class SolitaireGame extends Play {
865904
request_new_game() {
866905
this.back_res.new_game()
867906
}
868-
}
869907

870-
export { card_sort_key } from 'lsolitaire'
908+
909+
_update() {
910+
if (this.trigger_auto === -1) {
911+
this.trigger_auto = ticks.half + ticks.thirds
912+
} else if (this.trigger_auto > 0) {
913+
this.trigger_auto = appr(this.trigger_auto, 0, Time.delta)
914+
} else if (this.trigger_auto === 0) {
915+
this.trigger_auto = -2
916+
let hint_data = WasteToFoundation.auto_can(this.pov)
917+
if (hint_data) {
918+
this.cmd(WasteToFoundation, hint_data)
919+
this.trigger_auto = -3
920+
} else {
921+
for (let i = 0; i < 7; i++) {
922+
let hint_data = TableuToFoundation.auto_can(this.pov, {tableu: i})
923+
if (hint_data) {
924+
this.cmd(TableuToFoundation, hint_data)
925+
this.trigger_auto = -3
926+
break
927+
}
928+
}
929+
}
930+
}
931+
}
932+
}

0 commit comments

Comments
 (0)