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));
|
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 = {}) {
|
async getBestMove(options = {}) {
|
||||||
if (!this.isReady) throw new Error('Engine not ready');
|
if (!this.isReady) throw new Error('Engine not ready');
|
||||||
if (!this.currentFen) throw new Error('Position not set');
|
if (!this.currentFen) throw new Error('Position not set');
|
||||||
|
|
@ -152,6 +162,11 @@ class ChessEngine extends EventEmitter {
|
||||||
return { bestMove };
|
return { bestMove };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async createNewGame(){
|
||||||
|
await this.setNewGame();
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
quit() {
|
quit() {
|
||||||
if (this.engine) {
|
if (this.engine) {
|
||||||
this.sendCommand('quit');
|
this.sendCommand('quit');
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,7 @@ app.post('/validate', (req, res) => {
|
||||||
tempBoard.delete();
|
tempBoard.delete();
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
|
status: 'ok',
|
||||||
isValid,
|
isValid,
|
||||||
startingFen: ffish.startingFen(variant)
|
startingFen: ffish.startingFen(variant)
|
||||||
});
|
});
|
||||||
|
|
@ -181,7 +182,7 @@ app.post('/validate', (req, res) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// New game endpoint
|
// New game endpoint
|
||||||
app.post('/new', (req, res) => {
|
app.post('/new', async (req, res) => {
|
||||||
lastResponse = new Date().getTime()
|
lastResponse = new Date().getTime()
|
||||||
const { variant = 'chess' } = req.body;
|
const { variant = 'chess' } = req.body;
|
||||||
|
|
||||||
|
|
@ -192,6 +193,7 @@ app.post('/new', (req, res) => {
|
||||||
|
|
||||||
board = new ffish.Board(variant);
|
board = new ffish.Board(variant);
|
||||||
|
|
||||||
|
const engineAnalysis = await engine.createNewGame();
|
||||||
res.json({
|
res.json({
|
||||||
status: 'ok',
|
status: 'ok',
|
||||||
fen: board.fen(),
|
fen: board.fen(),
|
||||||
|
|
@ -311,6 +313,7 @@ app.get('/state', (req, res) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
res.json({
|
res.json({
|
||||||
|
status: 'ok',
|
||||||
fen: board.fen(),
|
fen: board.fen(),
|
||||||
legalMoves: board.legalMoves().split(' '),
|
legalMoves: board.legalMoves().split(' '),
|
||||||
legalMovesSan: board.legalMovesSan().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
|
// Analysis endpoint
|
||||||
app.post('/analyze', async (req, res) => {
|
app.post('/analyze', async (req, res) => {
|
||||||
lastResponse = new Date().getTime()
|
lastResponse = new Date().getTime()
|
||||||
|
|
@ -341,6 +368,7 @@ app.post('/analyze', async (req, res) => {
|
||||||
|
|
||||||
// Get basic position analysis
|
// Get basic position analysis
|
||||||
const positionAnalysis = {
|
const positionAnalysis = {
|
||||||
|
status: 'ok',
|
||||||
fen: board.fen(),
|
fen: board.fen(),
|
||||||
isCheck: board.isCheck(),
|
isCheck: board.isCheck(),
|
||||||
isGameOver: board.isGameOver(),
|
isGameOver: board.isGameOver(),
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ func _init():
|
||||||
cardName = "Supernova"
|
cardName = "Supernova"
|
||||||
rank = Rank.RANK_0
|
rank = Rank.RANK_0
|
||||||
effectType = EffectType.PIECE_EFFECT
|
effectType = EffectType.PIECE_EFFECT
|
||||||
duration = 5
|
duration = 1
|
||||||
description = "All enemy units within 4 radius are captured"
|
description = "All enemy units within 4 radius are captured"
|
||||||
unitWhitelist = ["King"]
|
unitWhitelist = ["King"]
|
||||||
remaining_turns = duration
|
remaining_turns = duration
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ const CARD_BASE_COSTS = {
|
||||||
func _init():
|
func _init():
|
||||||
print("************************DECK INIT*****************")
|
print("************************DECK INIT*****************")
|
||||||
initializeStartingDeck()
|
initializeStartingDeck()
|
||||||
initializeStartingBank()
|
# initializeStartingBank()
|
||||||
|
|
||||||
func initializeStartingDeck():
|
func initializeStartingDeck():
|
||||||
deck.clear();
|
deck.clear();
|
||||||
|
|
@ -44,7 +44,6 @@ func initializeStartingBank():
|
||||||
bank.append(DrunkDrivingCard.new())
|
bank.append(DrunkDrivingCard.new())
|
||||||
bank.append(SupernovaCard.new())
|
bank.append(SupernovaCard.new())
|
||||||
|
|
||||||
# Add some duplicates for testing
|
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
bank.append(HopscotchCard.new())
|
bank.append(HopscotchCard.new())
|
||||||
bank.append(FieryCapeCard.new())
|
bank.append(FieryCapeCard.new())
|
||||||
|
|
@ -65,7 +64,6 @@ func drawCard():
|
||||||
|
|
||||||
if !deck.is_empty() && hand.size() < hand_size:
|
if !deck.is_empty() && hand.size() < hand_size:
|
||||||
hand.append(deck.pop_back())
|
hand.append(deck.pop_back())
|
||||||
|
|
||||||
emit_signal("hand_updated", hand)
|
emit_signal("hand_updated", hand)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -86,6 +84,22 @@ func playCard(card: Card, target_piece: Pawn, board_flow = null, game_state = nu
|
||||||
hand.erase(card)
|
hand.erase(card)
|
||||||
emit_signal("hand_updated", hand)
|
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
|
return true
|
||||||
# print("Failed Play Card 2")
|
# print("Failed Play Card 2")
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,7 @@ func generateMove(think_time_ms: int = 1000) -> void:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func getGeneratedMove() -> Dictionary:
|
func getGeneratedMove() -> Dictionary:
|
||||||
var move = generated_move.duplicate()
|
var move = generated_move.duplicate()
|
||||||
generated_move.clear()
|
generated_move.clear()
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ var is_initialized: bool = false
|
||||||
@onready var turnIndicator: ColorRect = $TurnIndicator
|
@onready var turnIndicator: ColorRect = $TurnIndicator
|
||||||
@onready var p1String: RichTextLabel = $Player1Points
|
@onready var p1String: RichTextLabel = $Player1Points
|
||||||
@onready var p2String: RichTextLabel = $Player2Points
|
@onready var p2String: RichTextLabel = $Player2Points
|
||||||
@onready var gold: int = 1000
|
@onready var gold: int = 75
|
||||||
@onready var deckManager: DeckManager
|
@onready var deckManager: DeckManager
|
||||||
@onready var tileManager: TileManager
|
@onready var tileManager: TileManager
|
||||||
@onready var cameraController: CameraController
|
@onready var cameraController: CameraController
|
||||||
|
|
@ -103,6 +103,8 @@ func _on_new_game_requested(options = {}):
|
||||||
turnIndicator.visible = true
|
turnIndicator.visible = true
|
||||||
if options and "fen" in options:
|
if options and "fen" in options:
|
||||||
currentFen = options.fen
|
currentFen = options.fen
|
||||||
|
if "elo" in options:
|
||||||
|
cpuElo = options.elo
|
||||||
if cameraController:
|
if cameraController:
|
||||||
cameraController.reset_view()
|
cameraController.reset_view()
|
||||||
if is_initialized:
|
if is_initialized:
|
||||||
|
|
@ -115,6 +117,7 @@ func _on_new_game_requested(options = {}):
|
||||||
stateMachine.transitionToNextState(Constants.WHITE_TURN)
|
stateMachine.transitionToNextState(Constants.WHITE_TURN)
|
||||||
else:
|
else:
|
||||||
initialize_game_system()
|
initialize_game_system()
|
||||||
|
stockfishController.start_board(cpuElo)
|
||||||
|
|
||||||
func initialize_game_system():
|
func initialize_game_system():
|
||||||
print("Initializing game system")
|
print("Initializing game system")
|
||||||
|
|
@ -460,7 +463,6 @@ func resetBoard() -> void:
|
||||||
p2String.text = str(p2Points)
|
p2String.text = str(p2Points)
|
||||||
gamecheckMate = false;
|
gamecheckMate = false;
|
||||||
gamedraw = false;
|
gamedraw = false;
|
||||||
deckManager.initializeStartingDeck()
|
|
||||||
|
|
||||||
areas.clear()
|
areas.clear()
|
||||||
specialArea.clear()
|
specialArea.clear()
|
||||||
|
|
|
||||||
|
|
@ -55,10 +55,13 @@ func initialize(options = null):
|
||||||
populateBank()
|
populateBank()
|
||||||
|
|
||||||
func loadCards():
|
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:
|
if deckManager:
|
||||||
# Clone the deck to work with
|
# Clone the deck to work with
|
||||||
currentDeck = deckManager.deck.duplicate()
|
currentDeck = deckManager.deck.duplicate()
|
||||||
|
|
||||||
bankCards = deckManager.bank.duplicate()
|
bankCards = deckManager.bank.duplicate()
|
||||||
else:
|
else:
|
||||||
# Fallback with empty collections if deck manager not found
|
# Fallback with empty collections if deck manager not found
|
||||||
|
|
@ -201,3 +204,22 @@ func _on_backButton_pressed():
|
||||||
|
|
||||||
# Hide this screen
|
# 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