Skip to content

Commit

Permalink
made power menu show synergies and
Browse files Browse the repository at this point in the history
    added super exodia synergy
I still don't think css works properly
maybe I should redo it with proper testing
or I can hardcode for different resolutions
    since it would only require a few extra classes
  • Loading branch information
ajayvallurupalli committed Oct 17, 2024
1 parent 2ac8c42 commit d626083
Show file tree
Hide file tree
Showing 7 changed files with 2,403 additions and 1,606 deletions.
3,872 changes: 2,287 additions & 1,585 deletions app.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/extramoves.nim
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,7 @@ const giraffeMoves*: MoveProc = func (board: ChessBoard, p: Piece): Moves =
discard result.addIfFree(board, p.tile, shooterFactory(3,1))
discard result.addIfFree(board, p.tile, shooterFactory(3,-1))
discard result.addIfFree(board, p.tile, shooterFactory(-3,1))
discard result.addIfFree(board, p.tile, shooterFactory(-3,-1))
discard result.addIfFree(board, p.tile, shooterFactory(-3,-1))

const takeSelf*: MoveProc = func(board: ChessBoard, p: Piece): Moves =
result.add(p.tile)
16 changes: 9 additions & 7 deletions src/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ and give options for white and black
and make black options for shogi pieces
---increase max height for drafts
stop queen from taking itself with step on me
click enter to enter join code
]#

const iconsPath: string = "./icons/"
Expand All @@ -41,11 +41,11 @@ var peer: tuple[send: proc(data: cstring), destroy: proc()]
var side: Color#= white # = white only for testing, delete
var turn: bool# = true# = true#only for testing

var myDrafts: seq[Power]# = @[empress, putInTheWork, anime, illegalFormationBL, anime, anime, anime, wanderingRoninLeft]# = @[anime, illegalFormationBL]
var opponentDrafts: seq[Power]# = @[wanderingRoninLeft, anime, putInTheWork, empress]
var myDrafts: seq[Power]# = @[empress, sacrifice]# = @[anime, illegalFormationBL]
var opponentDrafts: seq[Power]# = @[stepOnMe, empress]
var draftOptions: seq[Power] = @[]
var draftChoices: int = 3
var drafts: int = 3
var drafts: int = 0

var theBoard: ChessBoard = startingBoard()
var selectedTile: Tile = (file: -1, rank: -1)
Expand Down Expand Up @@ -152,7 +152,9 @@ proc validateNotEmpty(field: kstring): proc () =

proc createTile(p: Piece, m: int, n: int): VNode =
var class = if (m*7+n) mod 2 == 0: "whiteTile" else: "blackTile"
if isSelected(m,n):
if isSelected(m, n) and possibleTakes.contains(p.tile):
class &= " can-take"
elif isSelected(m,n):
class &= " selected"
elif possibleMoves.contains(p.tile):
class &= " can-move"
Expand Down Expand Up @@ -330,11 +332,11 @@ proc createPowerSummary(p: Power): VNode =
proc createGame(): VNode =
result = buildHtml(tdiv(class="main")):
tdiv(class="column-scroll"):
for p in myDrafts:
for p in myDrafts.replaceAnySynergies():
createPowerSummary(p)
if side == white: createBoard() else: reverseBoard()
tdiv(class="column-scroll"):
for p in opponentDrafts:
for p in opponentDrafts.replaceAnySynergies():
createPowerSummary(p)

proc main(): VNode =
Expand Down
5 changes: 5 additions & 0 deletions src/piece.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const defaultOnEndTurn*: OnAction = proc (taker: Tile, taken: Tile, board: var C
discard nil

proc defaultWhenTake*(taker: Tile, taken: Tile, board: var ChessBoard): tuple[endTile: Tile, takeSuccess: bool] =
if (taker.file == taken.file) and (taker.rank == taken.file): return (taken, false) #stops pieces from taking themselves, though this can be overridden
board[taker.rank][taker.file].tile = taken
board[taken.rank][taken.file] = board[taker.rank][taker.file]
board[taker.rank][taker.file] = Piece(item: none, tile: taker)
Expand Down Expand Up @@ -106,6 +107,10 @@ proc pieceSwap*(p1: Piece, p2: Piece, board: var ChessBoard) =
board[p1.tile.rank][p1.tile.file].tile = (file: p1.tile.file, rank: p1.tile.rank)
board[temp.tile.rank][temp.tile.file].tile = (file: temp.tile.file, rank: temp.tile.rank)

proc piecePromote*(t: Tile, b: var ChessBoard) =
for f in b[t.rank][t.file].onPromote:
f(t, t, b)

func isAir*(p: Piece): bool =
return p.item == none

Expand Down
21 changes: 16 additions & 5 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 = "NONE"
icon*: FilePath = ""
onStart*: proc (drafterSide: Color, viewerSide: Color, b: var ChessBoard)
index*: int = -1
Expand Down Expand Up @@ -49,26 +49,30 @@ var
powers*: seq[Power] = @[emptyPower]
draftSynergies*: seq[Synergy]
secretSynergies*: seq[Synergy]
secretSecretSynergies*: seq[Synergy]
commonPowers*: seq[Power]
uncommonPowers*: seq[Power]
rarePowers*: seq[Power]
ultraRarePowers*: seq[Power]

proc registerSynergy*(s: Synergy, secret: bool = false, secretSecret = false) =
assert secret or not secretSecret #ensures that secret is true whenever secretSecret is true
var x = s
x.power.rarity = x.rarity
x.power.index = powers[powers.len - 1].index + 1
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
x.power.description = "Secret synergy! (" & str & ") -- " & x.power.description
elif not secret:
let str = s.replacements.foldr(a & " + " & b)
x.power.description = "Synergy! (" & str & ") " & x.power.description

powers.add(x.power)
if secret: secretSynergies.add(x) else: draftSynergies.add(x)
if secretSecret: secretSecretSynergies.add(x)
elif secret: secretSynergies.add(x)
else: draftSynergies.add(x)

proc synergize(pool: seq[Power], synergies: seq[Synergy], currentPowers: seq[Power], t: Tier, allTiers: bool = false): seq[Power] =
result = pool
Expand Down Expand Up @@ -127,5 +131,12 @@ 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.synergize(secretSynergies, drafts, Common, true).sortedByIt(it.priority):
d.onStart(draftSide, mySide, board)
for d in drafts.synergize(secretSynergies & secretSecretSynergies, drafts, Common, true).sortedByIt(it.priority):
d.onStart(draftSide, mySide, board)

proc replaceAnySynergies*(powers: seq[Power]): seq[Power] =
result = powers
for s in secretSynergies:
if powers.filterIt(it.name in s.requirements).len == s.requirements.len:
result = result.filterIt(it.name notin s.replacements)
result &= s.power
81 changes: 76 additions & 5 deletions src/powers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const empress*: Power = Power(
tier: Uncommon,
priority: 15,
description: "Your queen ascends, gaining the movement of a standard knight. ",
icon: "blackqueen.svg",
onStart:
proc (side: Color, viewSide: Color, b: var ChessBoard) =
for i in 0 ..< b.len:
Expand Down Expand Up @@ -93,7 +94,7 @@ const developed*: Power = Power(
b[6][4].pieceMove(5, 4, b)
)

const stepOnMe: Power = Power(
const stepOnMe*: Power = Power(
name: "Step on me",
tier: Common,
priority: 15,
Expand Down Expand Up @@ -256,7 +257,7 @@ const warewolves*: Power = Power(

const archBishops: Power = Power(
name: "Archbishops",
tier: Uncommon,
tier: Rare,
priority: 15,
description:
"""Your bishops ascend to archbishops, gaining the movement of a knight.""",
Expand All @@ -271,7 +272,7 @@ const archBishops: Power = Power(

const giraffe: Power = Power(
name: "Giraffe",
tier: Rare,
tier: Uncommon,
priority: 5,
description:
"""Your knights try riding giraffes. It works surprisingly well. Their leap is improved, moving 4 across instead of 2 across.""",
Expand Down Expand Up @@ -349,7 +350,74 @@ const masochistEmpress: Synergy = (
power: masochistEmpressPower,
rarity: 0,
requirements: @[empress.name, stepOnMe.name],
replacements: @[empress.name],
replacements: @[empress.name, stepOnMe.name],
index: -1
)

proc sacrificeWhenTaken*(taker: Tile, taken: Tile, board: var ChessBoard): tuple[endTile: Tile, takeSuccess: bool] =
if ((taker.file == taken.file) and (taker.rank == taken.rank)):
for i in 0..<board.len:
for j in 0..<board[0].len:
if board[i][j].sameColor(board[taker.rank][taker.file]):
piecePromote((file: j, rank: i), board)

board[taker.rank][taker.file].tile = taken
board[taken.rank][taken.file] = board[taker.rank][taker.file]
board[taker.rank][taker.file] = Piece(item: none, tile: taker)
board[taker.rank][taker.file].piecesTaken += 1
return ((taken.file, taken.rank), true)


const sacrifice*: Power = Power(
name: "Sacrificial Maiden",
tier: UltraRare,
priority: 20,
description: """SACRIFICE THY MAIDENS TO THE BLOOD GOD""",
icon: "blackqueen.svg",
onStart:
proc (side: Color, viewSide: Color, b: var ChessBoard) =
for i in 0 ..< b.len:
for j in 0 ..< b[0].len:
if b[i][j].item == queen and b[i][j].isColor(side):
b[i][j].whenTake = sacrificeWhenTaken
b[i][j].takes &= takeSelf
)

proc sacrificeWhenTakenEmpress*(taker: Tile, taken: Tile, board: var ChessBoard): tuple[endTile: Tile, takeSuccess: bool] =
if ((taker.file == taken.file) and (taker.rank == taken.rank)):
for i in 0..<board.len:
for j in 0..<board[0].len:
if board[i][j].sameColor(board[taker.rank][taker.file]):
piecePromote((file: j, rank: i), board)
board[i][j].moves &= knightMoves
board[i][j].takes &= knightTakes

board[taker.rank][taker.file].tile = taken
board[taken.rank][taken.file] = board[taker.rank][taker.file]
board[taker.rank][taker.file] = Piece(item: none, tile: taker)
board[taker.rank][taker.file].piecesTaken += 1
return ((taken.file, taken.rank), true)


const exodiaPower: Power = Power(
name: "Exodia",
tier: UltraRare,
priority: 0,
description: "You had your fun, but the game is over. Too bad right?",
onStart:
proc (side: Color, viewSide: Color, b: var ChessBoard) =
for i in 0 ..< b.len:
for j in 0 ..< b[0].len:
if b[i][j].item == queen and b[i][j].isColor(side):
b[i][j].whenTake = sacrificeWhenTakenEmpress
b[i][j].takes &= takeSelf
)

const exodia: Synergy = (
power: exodiaPower,
rarity: 0,
requirements: @[empress.name, sacrifice.name],
replacements: @[empress.name, sacrifice.name],
index: -1
)

Expand All @@ -368,6 +436,9 @@ registerPower(wanderingRoninRight)
registerPower(archBishops)
registerPower(warewolves)
registerPower(giraffe)
registerPower(sacrifice)
registerPower(calvary)

registerSynergy(samuraiSynergy)
registerSynergy(masochistEmpress, true, true)
registerSynergy(masochistEmpress, true, true)
registerSynergy(exodia, true, false)
9 changes: 6 additions & 3 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ img {

.power {
padding: 20px;
min-height: 60%;
min-height: 90%;
width: 180px;
min-width: 180px;

Expand All @@ -89,10 +89,12 @@ img {
padding: 35px;

overflow-y: scroll;
overflow-x: hidden;
overflow-x: scroll;
max-height: 70%;
min-height: 70%;
height: 70%;
max-width: 33%;
width: 33%;
transform: translateY(-5%);
}

Expand Down Expand Up @@ -134,9 +136,10 @@ img {
padding: 5px;
background-color: #F8F7F7;
justify-content: center;
height: 15%;
height: auto;
min-height: 15%;
min-width: 100%;
max-width: 100%;
text-wrap: wrap;
}

Expand Down

0 comments on commit d626083

Please sign in to comment.