Skip to content

Commit

Permalink
Display bot detection results on game page
Browse files Browse the repository at this point in the history
  • Loading branch information
RubyMineshaft committed Nov 15, 2023
1 parent 9d5c18f commit ea1bdf3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/views/Game/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import { GobanContainer } from "GobanContainer";
import { GobanContext } from "./goban_context";
import { is_valid_url } from "url_validation";
import { disableTouchAction, enableTouchAction } from "./touch_actions";
import { BotDetectionResults } from "./BotDetectionResults";

export function Game(): JSX.Element {
const params = useParams<"game_id" | "review_id" | "move_number">();
Expand Down Expand Up @@ -144,6 +145,8 @@ export function Game(): JSX.Element {
const show_title = useShowTitle(goban.current);
const [, set_undo_requested] = React.useState<number | undefined>();
const [, forceUpdate] = React.useState<number>();
const [bot_detection_results, set_bot_detection_results] = React.useState(null);
const [show_bot_detection_results, set_show_bot_detection_results] = React.useState(false);

/* Functions */
const getLocation = (): string => {
Expand Down Expand Up @@ -448,6 +451,10 @@ export function Game(): JSX.Element {
set_show_game_timing(!show_game_timing);
};

const toggleShowBotDetectionResults = () => {
set_show_bot_detection_results(!show_bot_detection_results);
};

const gameLogModalMarkCoords = (stones_string: string) => {
for (let i = 0; i < goban.current.config.width; i++) {
for (let j = 0; j < goban.current.config.height; j++) {
Expand Down Expand Up @@ -808,6 +815,18 @@ export function Game(): JSX.Element {
return null;
};

const frag_bot_detection_results = () => {
if (bot_detection_results?.ai_suspected.length > 0) {
return (
<BotDetectionResults
bot_detection_results={bot_detection_results}
game_id={game_id}
updateBotDetectionResults={set_bot_detection_results}
/>
);
}
};

const frag_timings = () => {
if (goban && goban.current.engine) {
return (
Expand Down Expand Up @@ -1298,6 +1317,7 @@ export function Game(): JSX.Element {
set_annulment_reason(game.annulment_reason);
set_historical_black(game.historical_ratings.black);
set_historical_white(game.historical_ratings.white);
set_bot_detection_results(game.bot_detection_results);

goban_div.current.setAttribute("data-game-id", game_id.toString());

Expand Down Expand Up @@ -1489,6 +1509,12 @@ export function Game(): JSX.Element {
zen_mode={zen_mode}
black_flags={black_flags}
white_flags={white_flags}
black_ai_suspected={bot_detection_results?.ai_suspected.includes(
historical_black.id,
)}
white_ai_suspected={bot_detection_results?.ai_suspected.includes(
historical_white.id,
)}
/>
)}

Expand Down Expand Up @@ -1531,6 +1557,8 @@ export function Game(): JSX.Element {
onTimingClicked={toggleShowTiming}
onCoordinatesMarked={gameLogModalMarkCoords}
onReviewClicked={startReview}
onDetectionResultsClicked={toggleShowBotDetectionResults}
ai_suspected={bot_detection_results?.ai_suspected.length > 0}
/>
)}
</div>
Expand All @@ -1546,6 +1574,12 @@ export function Game(): JSX.Element {
zen_mode={zen_mode}
black_flags={black_flags}
white_flags={white_flags}
black_ai_suspected={bot_detection_results?.ai_suspected.includes(
historical_black?.id,
)}
white_ai_suspected={bot_detection_results?.ai_suspected.includes(
historical_white?.id,
)}
/>
)}

Expand All @@ -1557,6 +1591,10 @@ export function Game(): JSX.Element {
show_game_timing &&
frag_timings()}

{(view_mode === "square" || view_mode === "wide" || null) &&
show_bot_detection_results &&
frag_bot_detection_results()}

{review ? frag_review_controls() : frag_play_controls(true)}

{(view_mode === "wide" || null) && CHAT}
Expand All @@ -1582,6 +1620,8 @@ export function Game(): JSX.Element {
onTimingClicked={toggleShowTiming}
onCoordinatesMarked={gameLogModalMarkCoords}
onReviewClicked={startReview}
onDetectionResultsClicked={toggleShowBotDetectionResults}
ai_suspected={bot_detection_results?.ai_suspected.length > 0}
/>
{(zen_mode || null) && <div className="align-col-end"></div>}
</div>
Expand Down
14 changes: 14 additions & 0 deletions src/views/Game/PlayerCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ interface PlayerCardsProps {
zen_mode: boolean;
black_flags: null | rest_api.GamePlayerFlags;
white_flags: null | rest_api.GamePlayerFlags;
black_ai_suspected: boolean;
white_ai_suspected: boolean;
}

export function PlayerCards({
Expand All @@ -55,6 +57,8 @@ export function PlayerCards({
zen_mode,
black_flags,
white_flags,
black_ai_suspected,
white_ai_suspected,
}: PlayerCardsProps): JSX.Element {
const goban = useGoban();
const engine = goban.engine;
Expand Down Expand Up @@ -107,6 +111,7 @@ export function PlayerCards({
onScoreClick={toggleScorePopup}
zen_mode={zen_mode}
flags={black_flags}
ai_suspected={black_ai_suspected}
/>
<PlayerCard
historical={historical_white}
Expand All @@ -117,6 +122,7 @@ export function PlayerCards({
onScoreClick={toggleScorePopup}
zen_mode={zen_mode}
flags={white_flags}
ai_suspected={white_ai_suspected}
/>
</div>
{(engine.rengo || null) && (
Expand Down Expand Up @@ -201,6 +207,7 @@ interface PlayerCardProps {
onScoreClick: () => void;
zen_mode: boolean;
flags: null | rest_api.GamePlayerFlags;
ai_suspected: boolean;
}

export function PlayerCard({
Expand All @@ -212,6 +219,7 @@ export function PlayerCard({
onScoreClick,
zen_mode,
flags,
ai_suspected,
}: PlayerCardProps) {
const engine = goban.engine;
const player = engine.players[color];
Expand Down Expand Up @@ -354,6 +362,12 @@ export function PlayerCard({
<div id={`${color}-score-details`} className="score-details">
<ScorePopup goban={goban} color={color} show={show_score_breakdown} />
</div>
{!hide_flags && ai_suspected && (
<div className="player-flags">
<i className="fa fa-flag" />
{" AI Suspected"}
</div>
)}
{!hide_flags && flags && (
<div className="player-flags">
{Object.keys(flags).map((flag) => (
Expand Down

0 comments on commit ea1bdf3

Please sign in to comment.