1
1
import { useEffect } from "react"
2
2
import GameService from "../../services/GameService"
3
3
4
- import { CARDS } from "../../model/Cards"
5
-
6
4
import { useAppDispatch , useAppSelector } from "../../caches/hooks"
7
5
import {
8
6
getCanBuyCards ,
@@ -12,60 +10,9 @@ import {
12
10
getIsMyGo ,
13
11
getRound ,
14
12
} from "../../caches/GameSlice"
15
- import { Round , RoundStatus } from "../../model/Round"
16
- import { Suit } from "../../model/Suit"
13
+ import { RoundStatus } from "../../model/Round"
17
14
import { getAutoPlayCard } from "../../caches/AutoPlaySlice"
18
-
19
- const bestCardLead = ( round : Round ) => {
20
- let trumpCards = CARDS . filter (
21
- c => c . suit === round . suit || c . suit === Suit . WILD ,
22
- )
23
-
24
- // Remove played trump cards
25
- round . completedHands . forEach ( hand => {
26
- hand . playedCards . forEach ( p => {
27
- const card = CARDS . find ( c => ( c . name = p . card ) )
28
- if (
29
- ( card && card . suit === round . suit ) ||
30
- p . card === "JOKER" ||
31
- p . card === "ACE_HEARTS"
32
- )
33
- trumpCards = trumpCards . filter ( c => p . card !== c . name )
34
- } )
35
- } )
36
-
37
- // Sort Descending
38
- trumpCards . sort ( ( a , b ) => b . value - a . value )
39
-
40
- return round . currentHand . leadOut === trumpCards [ 0 ] . name
41
- }
42
-
43
- const getWorstCard = ( cards : string [ ] , suit : Suit ) => {
44
- console . info ( `AutoAction -> followWorst` )
45
- const myCardsRich = CARDS . filter ( card => cards . some ( c => c === card . name ) )
46
- const myTrumpCards = myCardsRich . filter (
47
- card => card . suit === suit || card . suit === Suit . WILD ,
48
- )
49
-
50
- if ( myTrumpCards . length > 0 ) {
51
- // Sort ascending by value
52
- myTrumpCards . sort ( ( a , b ) => a . value - b . value )
53
- return myTrumpCards [ 0 ]
54
- } else {
55
- // Sort ascending by cold value
56
- myCardsRich . sort ( ( a , b ) => a . coldValue - b . coldValue )
57
-
58
- // if we can't find a cold card that is clearly the worst card then do nothing
59
- if (
60
- myCardsRich . length > 1 &&
61
- myCardsRich [ 0 ] . coldValue === myCardsRich [ 1 ] . coldValue
62
- ) {
63
- return
64
- }
65
-
66
- return myCardsRich [ 0 ]
67
- }
68
- }
15
+ import { bestCardLead , getWorstCard } from "../../utils/GameUtils"
69
16
70
17
const AutoActionManager = ( ) => {
71
18
const dispatch = useAppDispatch ( )
0 commit comments