Skip to content

Commit

Permalink
chore: cleaned coded and removed unused imports/variables
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinjosethomas committed Oct 25, 2024
1 parent bac11dd commit 110cf3e
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 95 deletions.
2 changes: 1 addition & 1 deletion src/components/AboutMaia/AboutMaia.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import personReid from './people/reid.jpg'
import personAshton from './people/ashton.jpeg'
import personJon from './people/jon.jpg'
import personSid from './people/sid.jpeg'
import personRussel from './people/russell.jpg'
// import personRussel from './people/russell.jpg'
import personJoseph from './people/joseph.jpg'
import personIsaac from './people/isaac.jpg'
import personDmitriy from './people/dmitriy.jpg'
Expand Down
9 changes: 1 addition & 8 deletions src/components/Feedback/Feedback.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { Chess } from 'chess.ts'
import {
useMemo,
useState,
Dispatch,
useEffect,
SetStateAction,
useCallback,
} from 'react'
import { useMemo, Dispatch, SetStateAction, useCallback } from 'react'

import { Markdown } from 'src/components'
import styles from './Feedback.module.scss'
Expand Down
5 changes: 3 additions & 2 deletions src/components/GameClock/GameClock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ export const GameClock: React.FC<Props> = (
) => {
const { theme } = useContext(ThemeContext)
const { user } = useContext(AuthContext)
const { timeControl, player, toPlay, whiteClock, blackClock, lastMoveTime } =
useContext(PlayControllerContext)
const { player, toPlay, whiteClock, blackClock, lastMoveTime } = useContext(
PlayControllerContext,
)

const [referenceTime, setReferenceTime] = useState<number>(Date.now())

Expand Down
1 change: 0 additions & 1 deletion src/components/GameplayInterface/GameplayInterface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { GameClock } from '../GameClock'
import classNames from 'classnames'
import { useUnload } from 'src/hooks/useUnload'
import { StatsDisplay } from '../StatsDisplay'
import { AllStats } from 'src/hooks/useStats'

interface Props {
boardShapes?: DrawShape[]
Expand Down
1 change: 0 additions & 1 deletion src/components/PromotionOverlay/PromotionOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ interface Props {
}

export const PromotionOverlay: React.FC<Props> = ({
player,
file,
selectPromotion,
}: Props) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/modals/InstructionsModal/InstructionsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ const titles = {
turing: 'Bot or Not',
}

// const placeholder = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum eget velit volutpat, efficitur velit sed, volutpat orci. Pellentesque magna libero, commodo a neque a, interdum fringilla lacus. Nulla bibendum scelerisque dignissim. Sed non mi ac ligula laoreet euismod in ut diam. Maecenas nunc dolor, congue et nisl a, placerat dignissim urna. Mauris pretium quis ante a tristique. Duis vulputate leo ac erat mollis finibus. Fusce leo neque, auctor a dignissim non, tristique quis tortor. Aenean faucibus lacus turpis, eget bibendum sem maximus vitae.`

const analysisModalText = `This is the Analysis page, where you can analyze both your own Lichess games and World Championship matches with Maia and Stockfish. Combining Maia analysis with Stockfish analysis gives you a more human-centered way to think about chess. For example, it can help you differentiate strong, findable moves from strong but impossible-to-find "engine" moves. It can also highlight tempting blunders that humans are likely to play. The movemap in the top-right visualizes all legal moves on a plane, where Stockfish-measured quality is on the x-axis and Maia probability is on the y-axis. Strong, findable moves are in the top right, "engine" moves are in the bottom right, and tempting blunders are in the top left. You can navigate to different games in the games panel, and you can play a position against Maia with the "Continue against Maia" button. Happy analyzing, and let us know if you find any bugs or want to see any improvements!`

const turingModalText = `Welcome to Bot-or-not, a fun Turing game where you see if you can tell human from machine. You will be shown games where one player is a human and the other player is a bot, and your job is to pick which side is the bot. You can browse the game in its entirety, and along with your guess you can submit an optional explanation of your reasoning. You will get a rating based on your accuracy, and you can see how you compare to other players on the leaderboard. Bots will also get ratings based on how often they trick humans. Have fun!`

const placeholder = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum eget velit volutpat, efficitur velit sed, volutpat orci. Pellentesque magna libero, commodo a neque a, interdum fringilla lacus. Nulla bibendum scelerisque dignissim. Sed non mi ac ligula laoreet euismod in ut diam. Maecenas nunc dolor, congue et nisl a, placerat dignissim urna. Mauris pretium quis ante a tristique. Duis vulputate leo ac erat mollis finibus. Fusce leo neque, auctor a dignissim non, tristique quis tortor. Aenean faucibus lacus turpis, eget bibendum sem maximus vitae.`

const handAndBrainModalText = `Here you can play Hand and Brain with Maia. In Hand and Brain chess, one player is the "brain" and decides which piece type to move (e.g. "pawn" or "rook") and the other player is the "hand" and chooses which move to make with that piece type (e.g. rook to c7). You can play as either the hand or the brain, and Maia will be your partner and play the other role. You will play against a team of Maias paired up with each other (one Maia will be the brain, and the other Maia will randomly decide which move to play, according to how often a human would play that move). You can also choose the level of Maia's play, from 1100 to 1900, for both your partner Maia and the opponent Maias. You will get both a Hand rating and a Brain rating based on your play. Have fun!`

const againstMaiaModalText = `Here you can play against Maia, our human-like chess engine. Maia is trained to play like a human at a specific skill level. You can choose the level of Maia's play, from 1100 to 1900, and you can also choose the time control of the game. You can also choose to play from a specific starting position, for example to practice a specific opening. You will get a Maia rating based on your play. Have fun!`
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useLocalStorage/useLocalStorage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useState } from 'react'
import { useState } from 'react'

export const useLocalStorage = <T>(
key: string,
Expand Down
13 changes: 2 additions & 11 deletions src/hooks/usePlayController/usePlayController.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useState, useMemo, useCallback, useEffect } from 'react'
import { Color, Move, Termination } from 'src/types'
import { Chess, Piece, SQUARES } from 'chess.ts'
import { PlayedGame, TimeControl, PlayGameConfig } from 'src/types/play'
import { startGame } from 'src/api'
import { PlayedGame, PlayGameConfig } from 'src/types/play'
import { AllStats } from '../useStats'

const nullFen = new Chess().fen()
Expand Down Expand Up @@ -87,15 +86,7 @@ const movesUciToGame = (

export const usePlayController = (
id: string,
{
player,
playType,
isBrain,
maiaVersion,
sampleMoves,
timeControl,
startFen,
}: PlayGameConfig,
{ player, playType, maiaVersion, timeControl, startFen }: PlayGameConfig,
) => {
const [moves, setMoves] = useState<string[]>([])
const [moveTimes, setMoveTimes] = useState<number[]>([])
Expand Down
1 change: 0 additions & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Head from 'next/head'
import Script from 'next/script'
import { useRouter } from 'next/router'
import type { AppProps } from 'next/app'
import { Analytics } from '@vercel/analytics/react'
Expand Down
22 changes: 4 additions & 18 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
import React, {
useCallback,
useContext,
useEffect,
useRef,
useState,
} from 'react'

import type { NextPage } from 'next'
import Head from 'next/head'
import Link from 'next/link'
import Image from 'next/image'
import classNames from 'classnames'
import type { NextPage } from 'next'
import React, { useCallback, useContext, useEffect, useRef } from 'react'

import maiaDiagram from './maia_diagram.png'
import { AuthContext, ModalContext } from 'src/contexts'
import { AuthenticatedWrapper } from 'src/components'
import { AboutMaia } from 'src/components/AboutMaia/AboutMaia'
import { ModalContext } from 'src/contexts'
import { HomeHero } from 'src/components/HomeHero/HomeHero'
import { AboutMaia } from 'src/components/AboutMaia/AboutMaia'

const Home: NextPage = () => {
const { user, connectLichess, logout } = useContext(AuthContext)

const { setPlaySetupModalProps } = useContext(ModalContext)

// Close play dialog if page closed
Expand Down
9 changes: 4 additions & 5 deletions src/pages/play/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { NextPage } from 'next'
import Head from 'next/head'
import styles from 'src/styles/App.module.scss'

import { NextPage } from 'next'
import { useRouter } from 'next/router'
import { useCallback, useContext, useEffect, useState } from 'react'
import { PlayType } from 'src/types/play'
import { useContext, useEffect, useState } from 'react'

import { ModalContext } from 'src/contexts'
import styles from 'src/styles/App.module.scss'

const PlayPage: NextPage = () => {
const router = useRouter()
Expand Down
15 changes: 8 additions & 7 deletions src/pages/play/maia.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { NextPage } from 'next/types'
import { usePlayController } from 'src/hooks/usePlayController'
import { GameplayInterface } from 'src/components/GameplayInterface'
import { useRouter } from 'next/router'
import { useContext, useEffect, useMemo } from 'react'

import {
startGame,
getGameMove,
submitGameMove,
getPlayPlayerStats,
} from 'src/api'
import { PlayControllerContext } from 'src/contexts/PlayControllerContext/PlayControllerContext'
import { PlayControls } from 'src/components/PlayControls'
import { useContext, useEffect, useMemo, useState } from 'react'
import { Color, PlayedGame, TimeControl, PlayGameConfig } from 'src/types'
import { useRouter } from 'next/router'
import { Loading } from 'src/components'
import { ModalContext } from 'src/contexts'
import { useStats } from 'src/hooks/useStats'
import { PlayControls } from 'src/components/PlayControls'
import { Color, TimeControl, PlayGameConfig } from 'src/types'
import { usePlayController } from 'src/hooks/usePlayController'
import { GameplayInterface } from 'src/components/GameplayInterface'
import { PlayControllerContext } from 'src/contexts/PlayControllerContext/PlayControllerContext'

const playStatsLoader = async () => {
const stats = await getPlayPlayerStats()
Expand Down
1 change: 0 additions & 1 deletion src/pages/train.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { AllStats, useStats } from 'src/hooks/useStats'
import { TrainingGame, Status } from 'src/types/training'
import { StatsDisplay } from 'src/components/StatsDisplay'
import { ModalContext, WindowSizeContext } from 'src/contexts'
import { MovesContainer } from 'src/components/MovesContainer'
import { GameBoard } from 'src/components/GameBoard/GameBoard'
import { HorizontalEvaluationBar } from 'src/components/HorizontalEvaluationBar'
import { GameControllerContext } from 'src/contexts/GameControllerContext/GameControllerContext'
Expand Down
8 changes: 4 additions & 4 deletions src/providers/ModalContextProvider/ModalContextProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useRouter } from 'next/router'
import { ComponentProps, ReactNode, useState } from 'react'

import { Modals } from 'src/types'
import { useLocalStorage } from 'src/hooks'
import { ComponentProps, ReactNode, useEffect, useState } from 'react'
import { ModalContext } from 'src/contexts'
import { InstructionsModal } from 'src/components'
import { PlaySetupModal } from 'src/components/modals/PlaySetupModal/PlaySetupModal'
import { ModalContext } from 'src/contexts'
import { Modals } from 'src/types'

export const ModalContextProvider: React.FC<{ children: ReactNode }> = ({
children,
Expand Down
64 changes: 32 additions & 32 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,40 @@ interface Player {
title: string | undefined
}

interface StockfishAnalysisMap {
[move: string]: {
evaluation: number | undefined
whiteMate: number | undefined
blackMate: number | undefined
winrate: number
}
}
// interface StockfishAnalysisMap {
// [move: string]: {
// evaluation: number | undefined
// whiteMate: number | undefined
// blackMate: number | undefined
// winrate: number
// }
// }

interface MaiaAnalysisMap {
[move: string]: number
}
// interface MaiaAnalysisMap {
// [move: string]: number
// }

interface AvailableMoves {
[move: string]: GameState
}
// interface AvailableMoves {
// [move: string]: GameState
// }

interface Game {
id: string
termination: Termination
gameStates: GameState[]
whitePlayer: Player | undefined
blackPlayer: Player | undefined
}
// interface Game {
// id: string
// termination: Termination
// gameStates: GameState[]
// whitePlayer: Player | undefined
// blackPlayer: Player | undefined
// }

interface AnalysisGame extends Game {
stockfishAnalyses: { [model: string]: StockfishAnalysisMap[] }[]
maiaAnalyses: { [model: string]: MaiaAnalysisMap[] }[]
availableMoves: AvailableMoves[]
}
// interface AnalysisGame extends Game {
// stockfishAnalyses: { [model: string]: StockfishAnalysisMap[] }[]
// maiaAnalyses: { [model: string]: MaiaAnalysisMap[] }[]
// availableMoves: AvailableMoves[]
// }

interface TrainingGame extends Game {
targetIndex: number
stockfishAnalyses: { [model: string]: StockfishAnalysisMap[] }
maiaAnalyses: { [model: string]: MaiaAnalysisMap[] }
availableMoves: AvailableMoves
}
// interface TrainingGame extends Game {
// targetIndex: number
// stockfishAnalyses: { [model: string]: StockfishAnalysisMap[] }
// maiaAnalyses: { [model: string]: MaiaAnalysisMap[] }
// availableMoves: AvailableMoves
// }

0 comments on commit 110cf3e

Please sign in to comment.