Skip to content

Commit d494a02

Browse files
committed
refactor
1 parent 31bf352 commit d494a02

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25+
26+
# todo
27+
todo.md

src/Components/ShowAllBoards/ShowAllBoards.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ interface ShowAllBoardsProps extends PropsWithChildren {
99
}
1010

1111
export default function ShowAllBoards(props: ShowAllBoardsProps) {
12-
1312
return (
1413
<ShowResultsContext.Consumer>
1514
{

src/Components/ShowCards/ShowCards.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

src/Utils/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import Board from "../models/Board";
12
import Card from "../models/Card";
2-
import Hand from "../models/Hand";
33
import { COLORS, NUMBER2COLORSHORT, RANK2CARD } from "./maps";
44
import { 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"];

src/models/Board.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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) {

src/views/Analysis/Analysis.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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
}

src/views/Analysis/OfflineBridgeSolver.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
import { useEffect, useState } from "react";
22
import ShowTricks from "../../Components/PlayBoard/ShowTricks";
3-
import Hand from "../../models/Hand";
43
import { analyzeOffline } from "../../Utils/utils";
4+
import Board from "../../models/Board";
55

66
interface BridgeSolverProps {
7-
allHands?: Hand[];
7+
board: Board;
88
}
99

1010
export 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} />

0 commit comments

Comments
 (0)