Skip to content

Commit

Permalink
Challenge: Electric Chess
Browse files Browse the repository at this point in the history
  • Loading branch information
neongreen committed Jul 23, 2023
1 parent 89b88d0 commit 38103dc
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 0 deletions.
57 changes: 57 additions & 0 deletions golden-games/30366eaf-28ed-4d78-af5b-1fc05c544886/depth-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
1. Nc3 +0.20
... Nc6 0.00
2. Nh3 +0.20
... Nh6 0.00
3. a4 +0.02
... a5 0.00
4. Ra2 +0.20
... Ra7 0.00
5. b4 +0.02
... axb4 -1.01
6. Bb2 -0.81
... bxc3 -4.02
7. dxc3 -2.97
... Rxa4 -3.99
8. Rxa4 +1.21
... b5 +1.19
9. Qxd7 +2.39
... Bxd7 -7.01
10. Kd2 -6.81
... bxa4 -12.02
11. e4 -12.00
... Bxh3 -15.20
12. Ke2 -15.20
... Bxg2 -16.20
13. Bxg2 -12.80
... Qd7 -13.00
14. f4 -12.98
... e5 -13.00
15. Ke3 -13.00
... exf4 -14.03
16. Kxf4 -13.00
... Ke7 -13.20
17. e5 -13.19
... Nxe5 -14.22
18. Kxe5 -11.02
... c5 -11.04
19. Ke4 -11.04
... f5 -11.06
20. Ke3 -11.06
... g5 -11.08
21. Ke2 -11.08
... Bg7 -11.28
22. Ke3 -11.28
... Bxc3 -12.29
23. Ke2 -12.29
... Bxb2 -15.49
24. Ke3 -15.49
... a3 -15.50
25. Ke2 -15.50
... a2 -15.51
26. Ke3 -15.51
... a1=Q -23.66
27. Ke2 -23.66
... Qxh1 -28.66
28. Ke3 -28.66
... Qxg2 -31.86
Challenge lost - no moves available
35 changes: 35 additions & 0 deletions golden-games/30366eaf-28ed-4d78-af5b-1fc05c544886/depth-2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
1. Nc3 0.00
... Nc6 +0.20
2. Nh3 0.00
... Nh6 +0.02
3. a4 0.00
... a5 +0.20
4. Ra2 0.00
... Ra7 +0.02
5. e4 0.00
... e5 +0.20
6. Qe2 0.00
... Qe7 +0.02
7. b3 -0.01
... b6 +0.20
8. Bb2 0.00
... Bb7 +0.02
9. d3 -0.01
... d6 +0.20
10. Kd2 0.00
... Kd7 +0.02
11. f3 -0.01
... f6 +0.02
12. g3 -0.01
... g6 +0.20
13. Bg2 0.00
... Bg7 +0.01
14. Ra3 -0.01
... Ra6 +0.01
15. Ra2 -0.01
... Ra7 +0.01
16. Ra3 +0.01
... Ra6 +0.01
17. Ra2 +0.01
... Ra7 +0.01
1-2/1-2
95 changes: 95 additions & 0 deletions golden-games/30366eaf-28ed-4d78-af5b-1fc05c544886/depth-3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
1. Nc3 +0.20
... Nc6 0.00
2. Nd5 +0.80
... Nd4 -0.80
3. c3 +1.01
... Nb5 -0.18
4. Qb3 +1.21
... c6 -0.81
5. e4 +0.41
... Nd6 -0.80
6. Qb4 +0.21
... a5 -3.01
7. Qc5 +0.19
... Nxe4 -4.03
8. b4 -6.79
... Nxc5 -10.00
9. bxc5 -9.80
... cxd5 -10.00
10. Bb5 -9.00
... e5 -10.85
11. Ba3 -8.82
... Ra7 -10.85
12. Nf3 -8.80
... Qf6 -11.25
13. Ke2 -8.80
... Nh6 -11.25
14. h4 -8.98
... Qf4 -11.23
15. d3 -8.97
... Qg4 -12.19
16. Rh2 -8.79
... Be7 -12.19
17. g3 -8.80
... f5 -12.20
18. Ke3 -8.98
... d4 -11.97
19. cxd4 -8.77
... exd4 -11.97
20. Nxd4 -7.95
... Bf6 -11.17
21. f4 -9.76
... Qxg3 -14.96
22. Nf3 -13.76
... Bxa1 -17.16
23. d4 -14.75
... Ng4 -19.95
24. Ke2 -16.75
... Nxh2 -19.95
25. Nxh2 -19.95
... Qxh2 -20.97
26. Kd3 -19.97
... Qh3 -23.15
27. Kc2 -22.15
... Qxa3 -24.17
28. Kd1 -23.37
... Qxa2 -25.36
29. Kc1 -24.37
... Qb2 -27.55
30. Kd1 -27.35
... Qxb5 -28.38
31. Kc2 -28.36
... Bxd4 -29.39
32. Kd2 -29.39
... Bxc5 -29.59
33. Kc2 -29.59
... Qc4 -30.42
34. Kb2 -30.41
... h5 -30.64
35. Ka1 -30.44
... Qxf4 -31.46
36. Ka2 -31.46
... Qxh4 -31.66
37. Ka1 -31.66
... Ke7 -31.86
38. Ka2 -31.86
... Qb4 -32.06
39. Ka1 -31.86
... Qd2 -32.06
40. Kb1 -32.06
... Rh7 -32.08
41. Ka1 -32.08
... b5 -32.28
42. Kb1 -32.28
... Bb7 -32.30
43. Ka1 -32.30
... d5 -32.32
44. Kb1 -32.32
... g5 -32.33
45. Ka1 -32.33
... a4 -32.34
46. Kb1 -32.34
... a3 -32.35
47. Ka1 #-1
... Qb2 #-1
0-1
69 changes: 69 additions & 0 deletions golden-games/30366eaf-28ed-4d78-af5b-1fc05c544886/depth-4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
1. Nc3 0.00
... c6 +0.21
2. Ne4 -0.81
... Qa5 +0.01
3. f4 -1.01
... Qb4 -0.01
4. Kf2 -3.81
... Qxe4 -2.78
5. d3 -3.99
... Qd4 -2.77
6. e3 -3.79
... Qa4 -2.76
7. b3 -3.78
... Qb4 -1.95
8. Qd2 -2.98
... Qxd2 -2.56
9. Bxd2 -2.76
... Nh6 -2.56
10. Be2 -2.75
... Na6 -1.77
11. d4 -2.77
... Nc7 -1.76
12. a4 -3.55
... f5 -1.94
13. Nh3 -2.58
... Ng4 -2.35
14. Bxg4 -2.58
... fxg4 -2.38
15. Ng5 -3.38
... h6 -2.57
16. Ne4 -3.39
... e6 -2.35
17. c4 -2.77
... Be7 -2.57
18. Kg3 -2.95
... d5 -2.59
19. Nf2 -2.98
... Bd7 -1.94
20. cxd5 -2.99
... exd5 -1.96
21. Nxg4 -3.18
... h5 -1.98
22. Ne5 -2.18
... Bf6 -1.78
23. h4 -2.97
... Bxe5 -1.94
24. fxe5 -2.76
... Rh6 -1.94
25. Rh2 -2.94
... Rg6 -1.94
26. Kf2 -2.94
... Ke7 -1.94
27. Bb4 -2.94
... Ke6 -0.95
28. Ke2 -3.16
... Na6 -1.94
29. e4 -5.34
... Nxb4 -5.14
30. Kf3 -6.36
... Rf8 -5.34
31. Ke2 -7.16
... dxe4 -5.35
32. Kd2 -7.56
... Rf2 -6.56
33. Kc3 -7.56
... Nd5 #-2
34. Kc4 #-1
... Rc2 #-1
0-1
33 changes: 33 additions & 0 deletions src/challenges/chess-simp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Coord } from '@/utils/coord'
import { Board } from '@/board'
import { pieceValue } from '@/eval/material'
import { users } from './users'
import { allConnected } from '@/utils/connected'

const _2022_09_26: Challenge = {
meta: {
Expand Down Expand Up @@ -567,6 +568,37 @@ class Challenge_2022_02_11 implements Challenge {
}
}

class Challenge_2023_05_23 implements Challenge {
meta = {
uuid: '30366eaf-28ed-4d78-af5b-1fc05c544886',
title: 'Electric Chess',
link: 'https://www.youtube.com/watch?v=7YhDEIgfveU',
challenge:
"Chess, but there's electrical engineering. Your king is the battery. Your pieces+pawns cannot move unless they are connected along a chain to the king.",
}

private connectedPieces(board: Board): Coord[] {
return allConnected({
start: board.kings.white,
neighbors: (c) =>
[c.n(), c.s(), c.e(), c.w(), c.ne(), c.nw(), c.se(), c.sw()].filter(
(x) => x.isValid() && isWhitePiece(board.at(x))
),
equals: (a, b) => a.equals(b),
})
}

isMoveAllowed: Challenge['isMoveAllowed'] = ({ board, move }) => {
const movers = getAllMovers(move)
const connected = this.connectedPieces(board)
return movers.every((mover) => connected.some((x) => x.equals(mover.from)))
}

highlightSquares: NonNullable<Challenge['highlightSquares']> = ({ board }) => {
return this.connectedPieces(board).map((coord) => ({ coord, color: 'blue' }))
}
}

/**
* All Chess Simp challenges.
*/
Expand All @@ -593,6 +625,7 @@ export const chessSimpChallenges: Map<Uuid, { meta: ChallengeMeta; create: () =>
() => new Challenge_2022_05_12() as Challenge,
() => _2022_05_24,
() => new Challenge_2022_05_30() as Challenge,
() => new Challenge_2023_05_23() as Challenge,
() => new Challenge_2022_05_31() as Challenge,
],
// Jun 2022
Expand Down
20 changes: 20 additions & 0 deletions src/utils/connected.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Find all connected nodes in a graph.
*/
export function allConnected<T>(options: {
start: T
neighbors: (x: T) => T[]
equals: (a: T, b: T) => boolean
}): T[] {
const { start, neighbors, equals } = options
const visited: T[] = []
const queue: T[] = [start]
while (queue.length > 0) {
const current = queue.shift()!
if (!visited.some((x) => equals(x, current))) {
visited.push(current)
queue.push(...neighbors(current))
}
}
return visited
}

1 comment on commit 38103dc

@vercel
Copy link

@vercel vercel bot commented on 38103dc Jul 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ches – ./

ches.vercel.app
ches-git-main-neongreen.vercel.app
ches-neongreen.vercel.app

Please sign in to comment.