Skip to content

Commit

Permalink
added giraffe power and implemented secret and secretsecret powers
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayvallurupalli committed Oct 15, 2024
1 parent a9ab9f1 commit 8a459a7
Show file tree
Hide file tree
Showing 6 changed files with 2,593 additions and 2,324 deletions.
4,580 changes: 2,352 additions & 2,228 deletions app.js

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions icons/blackgiraffe.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions icons/whitegiraffe.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 95 additions & 0 deletions src/extramoves.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import piece, basePieces, moves, board

const diagnalMoves*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
discard result.addIfFree(board, p.tile, shooterFactory(1,1))
discard result.addIfFree(board, p.tile, shooterFactory(-1,1))
discard result.addIfFree(board, p.tile, shooterFactory(1,-1))
discard result.addIfFree(board, p.tile, shooterFactory(-1,-1))

const diagnalTakes*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
discard result.addIfTake(board, p, p.tile, shooterFactory(1,1))
discard result.addIfTake(board, p, p.tile, shooterFactory(-1,1))
discard result.addIfTake(board, p, p.tile, shooterFactory(1,-1))
discard result.addIfTake(board, p, p.tile, shooterFactory(-1,-1))

const leftRightMoves*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
discard result.addIfFree(board, p.tile, tileLeft)
discard result.addIfFree(board, p.tile, tileRight)

const leftRightTakes*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
discard result.addIfTake(board, p, p.tile, tileLeft)
discard result.addIfTake(board, p, p.tile, tileRight)

const whiteForwardMoves*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
discard result.addIfFree(board, p.tile, tileAbove)

const blackForwardMoves*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
discard result.addIfFree(board, p.tile, tileBelow)

const whiteForwardTakes*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
discard result.addIfTake(board, p, p.tile, tileAbove)

const blackForwardTakes*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
discard result.addIfTake(board, p, p.tile, tileBelow)

const whiteForwardTwiceTakes*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
let next = result.addIfTake(board, p, p.tile, tileAbove)
if next:
discard result.addIfTake(board, p, p.tile.tileAbove(), tileAbove)

const blackForwardTwiceTakes*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
let next = result.addIfTake(board, p, p.tile, tileBelow)
if next:
discard result.addIfTake(board, p, p.tile.tileBelow(), tileBelow)

const whiteForwardTwiceMoves*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
let next = result.addIfFree(board, p.tile, tileAbove)
if next:
discard result.addIfFree(board, p.tile.tileAbove(), tileAbove)

const blackForwardTwiceMoves*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
let next = result.addIfFree(board, p.tile, tileBelow)
if next:
discard result.addIfFree(board, p.tile.tileBelow(), tileBelow)



const cannibalRookTakes*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
result.add(lineTakes(board, p, tileAbove, cannibalismFlag = true))
result.add(lineTakes(board, p, tileBelow, cannibalismFlag = true))
result.add(lineTakes(board, p, tileLeft, cannibalismFlag = true))
result.add(lineTakes(board, p, tileRight, cannibalismFlag = true))

const cannibalBishopTakes*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
result.add(lineTakes(board, p, shooterFactory(1, 1), cannibalismFlag = true))
result.add(lineTakes(board, p, shooterFactory(-1, 1), cannibalismFlag = true))
result.add(lineTakes(board, p, shooterFactory(1, -1), cannibalismFlag = true))
result.add(lineTakes(board, p, shooterFactory(-1, -1), cannibalismFlag = true))

const cannibalKingTakes*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
for i in -1..1:
for j in -1..1:
discard result.addIfTake(board, p, p.tile, shooterFactory(i,j), cannibalismFlag = true)

const cannibalKnightTakes*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
discard result.addIfTake(board, p, p.tile, shooterFactory(1, 2), cannibalismFlag = true)
discard result.addIfTake(board, p, p.tile, shooterFactory(-1, 2), cannibalismFlag = true)
discard result.addIfTake(board, p, p.tile, shooterFactory(2, 1), cannibalismFlag = true)
discard result.addIfTake(board, p, p.tile, shooterFactory(2, -1), cannibalismFlag = true)
discard result.addIfTake(board, p, p.tile, shooterFactory(1, -2), cannibalismFlag = true)
discard result.addIfTake(board, p, p.tile, shooterFactory(-1, -2), cannibalismFlag = true)
discard result.addIfTake(board, p, p.tile, shooterFactory(-2, 1), cannibalismFlag = true)
discard result.addIfTake(board, p, p.tile, shooterFactory(-2, -1), cannibalismFlag = true)


const giraffeTakes*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
discard result.addIfTake(board, p, p.tile, shooterFactory(1,4))
discard result.addIfTake(board, p, p.tile, shooterFactory(-1,4))
discard result.addIfTake(board, p, p.tile, shooterFactory(1,-4))
discard result.addIfTake(board, p, p.tile, shooterFactory(-1,-4))

const giraffeMoves*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
discard result.addIfFree(board, p.tile, shooterFactory(1,4))
discard result.addIfFree(board, p.tile, shooterFactory(-1,4))
discard result.addIfFree(board, p.tile, shooterFactory(1,-4))
discard result.addIfFree(board, p.tile, shooterFactory(-1,-4))
31 changes: 17 additions & 14 deletions src/power.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type
synergy*: bool = true
tier*: Tier
rarity*: int = 8
description*: string
description*: string = ""
icon*: FilePath = ""
onStart*: proc (drafterSide: Color, viewerSide: Color, b: var ChessBoard)
index*: int = -1
Expand All @@ -23,7 +23,7 @@ type
power: Power
rarity: int
requirements: seq[string]
replacements: seq[string] = @[]
replacements: seq[string]
index: int

TierWeights* = tuple
Expand All @@ -47,30 +47,34 @@ const emptyPower: Power = Power(

var
powers*: seq[Power] = @[emptyPower]
synergies*: seq[Synergy]
draftSynergies*: seq[Synergy]
secretSynergies*: seq[Synergy]
commonPowers*: seq[Power]
uncommonPowers*: seq[Power]
rarePowers*: seq[Power]
ultraRarePowers*: seq[Power]

func `>`(a: Power, b: Power): bool =
return a.priority > b.priority

proc registerSynergy*(s: Synergy) =
proc registerSynergy*(s: Synergy, secret: bool = false, secretSecret = false) =
var x = s
x.power.rarity = x.rarity
x.power.index = powers[powers.len - 1].index + 1
x.power.description = "Synergy! " & x.power.description
x.index = x.power.index

if secret and not secretSecret:
let str = s.replacements.foldr(a & " + " & b)
x.power.description = "Secret synergy! (" & str & ") " & x.power.description
elif not secret:
let str = s.replacements.foldr(a & " + " & b)
x.power.description = "Snergy! (" & str & ") " & x.power.description

powers.add(x.power)
synergies.add(x)
if secret: secretSynergies.add(x) else: draftSynergies.add(x)

proc synergize(pool: seq[Power], currentPowers: seq[Power], t: Tier): seq[Power] =
proc synergize(pool: seq[Power], synergies: seq[Synergy], currentPowers: seq[Power], t: Tier, allTiers: bool = false): seq[Power] =
result = pool
for s in synergies:
if currentPowers.filterIt(it.name in s.requirements).len == s.requirements.len and
s.power.tier == t:
(s.power.tier == t or allTiers):
if s.replacements.len == 0:
result &= powers[s.index]
else:
Expand All @@ -91,8 +95,7 @@ proc registerPower*(p: Power) =
seqOf(x.tier).add(x)

proc randomPower(t: Tier, currentPowers: seq[Power], alreadySelected: seq[Power] = @[]): Power =
let search = seqOf(t).filterIt(it.name notin alreadySelected.mapIt(it.name)).synergize(currentPowers, t)
echo "search: ", search, "\n"
let search = seqOf(t).filterIt(it.name notin alreadySelected.mapIt(it.name)).synergize(draftSynergies, currentPowers, t)
if search.len == 0: return emptyPower

let sum = foldr(search.mapIt(it.rarity), a + b)
Expand Down Expand Up @@ -124,5 +127,5 @@ proc draftRandomPower*(allSelected: seq[Power], drafterSelected: seq[Power], opt
result.add(randomPower(randomTier(weights), drafterSelected, allSelected & result))

proc executeOn*(drafts: seq[Power], draftSide: Color, mySide: Color, board: var ChessBoard) =
for d in drafts.sortedByIt(it.priority):
for d in drafts.synergize(secretSynergies, drafts, Common, true).sortedByIt(it.priority):
d.onStart(draftSide, mySide, board)
Loading

0 comments on commit 8a459a7

Please sign in to comment.