fixed deck not persisting between nodes
This commit is contained in:
parent
a3311c79a7
commit
401d915a0b
7 changed files with 91 additions and 9 deletions
|
|
@ -120,6 +120,16 @@ class ChessEngine extends EventEmitter {
|
|||
await new Promise(resolve => this.once('ready', resolve));
|
||||
}
|
||||
|
||||
async setNewGame() {
|
||||
if (!this.isReady) throw new Error('Engine not ready');
|
||||
|
||||
this.sendCommand(`ucinewgame`);
|
||||
|
||||
// Ensure engine is ready after position set
|
||||
this.sendCommand('isready');
|
||||
await new Promise(resolve => this.once('ready', resolve));
|
||||
}
|
||||
|
||||
async getBestMove(options = {}) {
|
||||
if (!this.isReady) throw new Error('Engine not ready');
|
||||
if (!this.currentFen) throw new Error('Position not set');
|
||||
|
|
@ -152,6 +162,11 @@ class ChessEngine extends EventEmitter {
|
|||
return { bestMove };
|
||||
}
|
||||
|
||||
async createNewGame(){
|
||||
await this.setNewGame();
|
||||
return true
|
||||
}
|
||||
|
||||
quit() {
|
||||
if (this.engine) {
|
||||
this.sendCommand('quit');
|
||||
|
|
|
|||
|
|
@ -172,6 +172,7 @@ app.post('/validate', (req, res) => {
|
|||
tempBoard.delete();
|
||||
|
||||
res.json({
|
||||
status: 'ok',
|
||||
isValid,
|
||||
startingFen: ffish.startingFen(variant)
|
||||
});
|
||||
|
|
@ -181,7 +182,7 @@ app.post('/validate', (req, res) => {
|
|||
});
|
||||
|
||||
// New game endpoint
|
||||
app.post('/new', (req, res) => {
|
||||
app.post('/new', async (req, res) => {
|
||||
lastResponse = new Date().getTime()
|
||||
const { variant = 'chess' } = req.body;
|
||||
|
||||
|
|
@ -192,6 +193,7 @@ app.post('/new', (req, res) => {
|
|||
|
||||
board = new ffish.Board(variant);
|
||||
|
||||
const engineAnalysis = await engine.createNewGame();
|
||||
res.json({
|
||||
status: 'ok',
|
||||
fen: board.fen(),
|
||||
|
|
@ -311,6 +313,7 @@ app.get('/state', (req, res) => {
|
|||
|
||||
try {
|
||||
res.json({
|
||||
status: 'ok',
|
||||
fen: board.fen(),
|
||||
legalMoves: board.legalMoves().split(' '),
|
||||
legalMovesSan: board.legalMovesSan().split(' '),
|
||||
|
|
@ -329,6 +332,30 @@ app.get('/state', (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
/*
|
||||
createNewGame
|
||||
*/
|
||||
app.post('/newgame', async (req, res) => {
|
||||
lastResponse = new Date().getTime()
|
||||
|
||||
|
||||
try {
|
||||
|
||||
const response = {
|
||||
status: 'ok',
|
||||
};
|
||||
|
||||
// If engine is available, get engine analysis
|
||||
if (engine && engine.isReady) {
|
||||
const engineAnalysis = await engine.createNewGame();
|
||||
}
|
||||
|
||||
res.json(response);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Analysis endpoint
|
||||
app.post('/analyze', async (req, res) => {
|
||||
lastResponse = new Date().getTime()
|
||||
|
|
@ -341,6 +368,7 @@ app.post('/analyze', async (req, res) => {
|
|||
|
||||
// Get basic position analysis
|
||||
const positionAnalysis = {
|
||||
status: 'ok',
|
||||
fen: board.fen(),
|
||||
isCheck: board.isCheck(),
|
||||
isGameOver: board.isGameOver(),
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ func _init():
|
|||
cardName = "Supernova"
|
||||
rank = Rank.RANK_0
|
||||
effectType = EffectType.PIECE_EFFECT
|
||||
duration = 5
|
||||
duration = 1
|
||||
description = "All enemy units within 4 radius are captured"
|
||||
unitWhitelist = ["King"]
|
||||
remaining_turns = duration
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ const CARD_BASE_COSTS = {
|
|||
func _init():
|
||||
print("************************DECK INIT*****************")
|
||||
initializeStartingDeck()
|
||||
initializeStartingBank()
|
||||
# initializeStartingBank()
|
||||
|
||||
func initializeStartingDeck():
|
||||
deck.clear();
|
||||
|
|
@ -44,7 +44,6 @@ func initializeStartingBank():
|
|||
bank.append(DrunkDrivingCard.new())
|
||||
bank.append(SupernovaCard.new())
|
||||
|
||||
# Add some duplicates for testing
|
||||
for i in range(3):
|
||||
bank.append(HopscotchCard.new())
|
||||
bank.append(FieryCapeCard.new())
|
||||
|
|
@ -65,7 +64,6 @@ func drawCard():
|
|||
|
||||
if !deck.is_empty() && hand.size() < hand_size:
|
||||
hand.append(deck.pop_back())
|
||||
|
||||
emit_signal("hand_updated", hand)
|
||||
|
||||
|
||||
|
|
@ -85,6 +83,22 @@ func playCard(card: Card, target_piece: Pawn, board_flow = null, game_state = nu
|
|||
attached_cards[target_piece.get_instance_id()] = card
|
||||
hand.erase(card)
|
||||
emit_signal("hand_updated", hand)
|
||||
|
||||
# match card.rank:
|
||||
# Card.Rank.RANK_0:
|
||||
# print("Rank 3 Burned permanently")
|
||||
# pass
|
||||
# Card.Rank.RANK_1:
|
||||
# print("Rank 3 Burned until next match")
|
||||
# pass
|
||||
# Card.Rank.RANK_2:
|
||||
# print("Rank 2 add to Discard")
|
||||
# discard.append(card)
|
||||
# pass
|
||||
# Card.Rank.RANK_3:
|
||||
# deck.append(card)
|
||||
# print("Rank 3 add to Deck")
|
||||
# pass
|
||||
|
||||
|
||||
return true
|
||||
|
|
|
|||
|
|
@ -170,6 +170,7 @@ func generateMove(think_time_ms: int = 1000) -> void:
|
|||
body
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ var is_initialized: bool = false
|
|||
@onready var turnIndicator: ColorRect = $TurnIndicator
|
||||
@onready var p1String: RichTextLabel = $Player1Points
|
||||
@onready var p2String: RichTextLabel = $Player2Points
|
||||
@onready var gold: int = 1000
|
||||
@onready var gold: int = 75
|
||||
@onready var deckManager: DeckManager
|
||||
@onready var tileManager: TileManager
|
||||
@onready var cameraController: CameraController
|
||||
|
|
@ -103,6 +103,8 @@ func _on_new_game_requested(options = {}):
|
|||
turnIndicator.visible = true
|
||||
if options and "fen" in options:
|
||||
currentFen = options.fen
|
||||
if "elo" in options:
|
||||
cpuElo = options.elo
|
||||
if cameraController:
|
||||
cameraController.reset_view()
|
||||
if is_initialized:
|
||||
|
|
@ -115,6 +117,7 @@ func _on_new_game_requested(options = {}):
|
|||
stateMachine.transitionToNextState(Constants.WHITE_TURN)
|
||||
else:
|
||||
initialize_game_system()
|
||||
stockfishController.start_board(cpuElo)
|
||||
|
||||
func initialize_game_system():
|
||||
print("Initializing game system")
|
||||
|
|
@ -460,7 +463,6 @@ func resetBoard() -> void:
|
|||
p2String.text = str(p2Points)
|
||||
gamecheckMate = false;
|
||||
gamedraw = false;
|
||||
deckManager.initializeStartingDeck()
|
||||
|
||||
areas.clear()
|
||||
specialArea.clear()
|
||||
|
|
|
|||
|
|
@ -55,10 +55,13 @@ func initialize(options = null):
|
|||
populateBank()
|
||||
|
||||
func loadCards():
|
||||
var board = get_node_or_null("/root/Board") as ChessGame
|
||||
if board and "deckManager" in board:
|
||||
deckManager = board.deckManager
|
||||
print("Found deck manager:", deckManager)
|
||||
if deckManager:
|
||||
# Clone the deck to work with
|
||||
currentDeck = deckManager.deck.duplicate()
|
||||
|
||||
bankCards = deckManager.bank.duplicate()
|
||||
else:
|
||||
# Fallback with empty collections if deck manager not found
|
||||
|
|
@ -200,4 +203,23 @@ func _on_backButton_pressed():
|
|||
emit_signal("back_pressed")
|
||||
|
||||
# Hide this screen
|
||||
visible = false
|
||||
visible = false
|
||||
|
||||
|
||||
|
||||
|
||||
# Notification
|
||||
func _notification(what):
|
||||
if what == NOTIFICATION_VISIBILITY_CHANGED:
|
||||
_on_visibility_changed(visible)
|
||||
|
||||
func _on_visibility_changed(is_visible):
|
||||
|
||||
print("DeckManager visibility changed to: ", is_visible)
|
||||
if is_visible:
|
||||
loadCards()
|
||||
setupDeckGrid()
|
||||
else:
|
||||
print("DeckManager is now invisible")
|
||||
|
||||
emit_signal("deck_manager_visibility_changed", is_visible)
|
||||
Loading…
Reference in a new issue