File tree Expand file tree Collapse file tree 7 files changed +20
-15
lines changed
Expand file tree Collapse file tree 7 files changed +20
-15
lines changed Original file line number Diff line number Diff line change @@ -22,3 +22,6 @@ dist-ssr
2222* .njsproj
2323* .sln
2424* .sw ?
25+
26+ # todo
27+ todo.md
Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ interface ShowAllBoardsProps extends PropsWithChildren {
99}
1010
1111export default function ShowAllBoards ( props : ShowAllBoardsProps ) {
12-
1312 return (
1413 < ShowResultsContext . Consumer >
1514 {
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ export default function ShowCards(props: ShowCardsProps) {
2525 < div className = "predicted" > { children } </ div >
2626 { dds &&
2727 < div className = "double-dummy" >
28- < Suspense fallback = { < div > Loading...</ div > } > < OfflineBridgeSolver allHands = { allHands } /> </ Suspense >
28+ < Suspense fallback = { < div > Loading...</ div > } > < OfflineBridgeSolver board = { board } /> </ Suspense >
2929 </ div >
3030 }
3131
Original file line number Diff line number Diff line change 1+ import Board from "../models/Board" ;
12import Card from "../models/Card" ;
2- import Hand from "../models/Hand" ;
33import { COLORS , NUMBER2COLORSHORT , RANK2CARD } from "./maps" ;
44import { convertAllHandsToPBN } from "./PBN" ;
55
@@ -12,9 +12,9 @@ export function card2idx(card: Card): number {
1212 return Card . RANK [ card . rank ] + 13 * ( NUMBER2COLORSHORT [ card . suit ] ) ;
1313}
1414
15- export function analyzeOffline ( allHands : Hand [ ] ) {
15+ export function analyzeOffline ( board : Board ) : Promise < ( string | number ) [ ] [ ] > {
1616 // @ts -ignore
17- const res = calcDDTable ( convertAllHandsToPBN ( allHands ) ) ;
17+ const res = calcDDTable ( convertAllHandsToPBN ( board . getAllHands ( ) ) ) ;
1818 const table = new Array ( 4 ) . fill ( 0 ) . map ( ( ) => new Array ( 5 ) . fill ( "*" ) ) ;
1919 table [ 0 ] [ 0 ] = res [ "N" ] [ "N" ] ;
2020 table [ 0 ] [ 1 ] = res [ "S" ] [ "N" ] ;
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ export default class Board {
2626 Shand : Hand ;
2727 Ehand : Hand ;
2828 Whand : Hand ;
29- ddsTricks ?: string | ( string | number ) [ ] [ ] ;
29+ ddsTricks ?: ( string | number ) [ ] [ ] ;
3030 pbn ?: string ;
3131
3232 constructor ( boardnum : number ) {
Original file line number Diff line number Diff line change @@ -36,9 +36,9 @@ function Analysis() {
3636 async function countTricks ( ) {
3737 for ( const board of all_boards ) {
3838 if ( ! board . ddsTricks ) {
39- board . ddsTricks = await analyzeOffline ( board . getAllHands ( ) ) ;
39+ board . ddsTricks = await analyzeOffline ( board ) ;
4040 }
41- tmp = MatrixAdd ( tmp , board . ddsTricks as ( string | number ) [ ] [ ] ) ;
41+ tmp = MatrixAdd ( tmp , board . ddsTricks ) ;
4242 }
4343 return Promise . resolve ( tmp ) ;
4444 }
Original file line number Diff line number Diff line change 11import { useEffect , useState } from "react" ;
22import ShowTricks from "../../Components/PlayBoard/ShowTricks" ;
3- import Hand from "../../models/Hand" ;
43import { analyzeOffline } from "../../Utils/utils" ;
4+ import Board from "../../models/Board" ;
55
66interface BridgeSolverProps {
7- allHands ?: Hand [ ] ;
7+ board : Board ;
88}
99
1010export default function OfflineBridgeSolver ( props : BridgeSolverProps ) {
11- const { allHands = [ ] } = props ;
11+ const { board } = props ;
1212 const [ ddtricks , setDDtricks ] = useState < ( string | number ) [ ] [ ] > ( ) ;
1313
1414 useEffect ( ( ) => {
15- analyzeOffline ( allHands ) . then ( ( res ) => {
16- setDDtricks ( res ) ;
17- } )
18- } , [ allHands ] ) ;
15+ if ( ! board . ddsTricks ) {
16+ analyzeOffline ( board ) . then ( ( res ) => {
17+ board . ddsTricks = res ;
18+ } )
19+ }
20+ setDDtricks ( board . ddsTricks ) ;
21+ } , [ board ] ) ;
1922
2023 return (
2124 < ShowTricks ddtricks = { ddtricks } />
You can’t perform that action at this time.
0 commit comments