User prompt
Kurulların üstüne rules yaz
User prompt
Copy butonu çok az aşağı çek
User prompt
Yukarı çek Copy position text
User prompt
Copy yazısını yukarı çek
User prompt
Copy butonunu çok az aşağı çek
User prompt
Copy butonunu da aynı hizaya getir
User prompt
Reset butonunu çok az aşağı çek
User prompt
Ekrana ekle sayısal değerini
User prompt
Tahtayı 8x2 ye düşür
User prompt
Piyonlar diğer taşların bir önünde dursun
User prompt
Piyonlar bir öne
User prompt
Piyonlar 2 öne
User prompt
Piyonlar bir arkaya
User prompt
Piyon emojilerini kaldır 2.yataya ekle
User prompt
Öne piyonlar ekle
Code edit (1 edits merged)
Please save this source code
User prompt
Chess960 Random Position Generator
Initial prompt
Satranç960 turnuvaları için rastgele bir konum başlatıcı
/**** * Classes ****/ var ActionButton = Container.expand(function (text, color, callback) { var self = Container.call(this); var bg = self.attachAsset(color === 'green' ? 'copyButtonBg' : 'resetButtonBg', { anchorX: 0.5, anchorY: 0.5 }); var buttonText = new Text2(text, { size: 28, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.callback = callback; self.down = function (x, y, obj) { if (self.callback) { self.callback(); } }; return self; }); var ChessSquare = Container.expand(function (isLight, x, y) { var self = Container.call(this); var square = self.attachAsset(isLight ? 'chessSquareLight' : 'chessSquareDark', { anchorX: 0, anchorY: 0 }); self.squareX = x; self.squareY = y; self.isLight = isLight; self.piece = null; self.pieceText = null; self.setPiece = function (pieceSymbol) { if (self.pieceText) { self.removeChild(self.pieceText); } if (pieceSymbol) { self.piece = pieceSymbol; self.pieceText = new Text2(pieceSymbol, { size: 120, fill: 0x000000 }); self.pieceText.anchor.set(0.5, 0.5); self.pieceText.x = square.width / 2; self.pieceText.y = square.height / 2; self.addChild(self.pieceText); } else { self.piece = null; self.pieceText = null; } }; return self; }); var GenerateButton = Container.expand(function (callback) { var self = Container.call(this); var bg = self.attachAsset('buttonBg', { anchorX: 0.5, anchorY: 0.5 }); var text = new Text2('Generate New Position', { size: 36, fill: 0xFFFFFF }); text.anchor.set(0.5, 0.5); self.addChild(text); self.callback = callback; self.down = function (x, y, obj) { if (self.callback) { self.callback(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2c3e50 }); /**** * Game Code ****/ var boardSquares = []; var currentPosition = ''; var positionText = null; // Chess piece symbols var pieceSymbols = { 'K': '♔', // King 'Q': '♕', // Queen 'R': '♖', // Rook 'B': '♗', // Bishop 'N': '♘' // Knight }; // Standard Chess960 pieces that need to be placed var piecesToPlace = ['R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R']; function initializeBoard() { var boardSize = 1600; // 8 squares * 200px each var startX = (2048 - boardSize) / 2; var startY = 400; // Create 4 ranks: 8, 7, 2, 1 (back ranks + pawn ranks) for (var rank = 0; rank < 4; rank++) { // Show ranks 8, 7, 2, 1 for (var file = 0; file < 8; file++) { var isLight = (rank + file) % 2 === 0; var square = new ChessSquare(isLight, file, rank); square.x = startX + file * 200; square.y = startY + rank * 200; game.addChild(square); if (rank === 0) { // Only store rank 8 squares for piece placement boardSquares.push(square); } // Add pawns to rank 7 (black pawns) and rank 2 (white pawns) if (rank === 1) { // Rank 7 - black pawns square.setPiece('♟'); } if (rank === 2) { // Rank 2 - white pawns square.setPiece('♙'); } } } } function generateChess960Position() { // Clear current pieces for (var i = 0; i < boardSquares.length; i++) { boardSquares[i].setPiece(null); } var position = new Array(8); var availableSquares = [0, 1, 2, 3, 4, 5, 6, 7]; // Step 1: Place bishops on opposite colored squares var lightSquares = [1, 3, 5, 7]; // Light squares var darkSquares = [0, 2, 4, 6]; // Dark squares // Place first bishop on light square var lightBishopPos = lightSquares[Math.floor(Math.random() * lightSquares.length)]; position[lightBishopPos] = 'B'; availableSquares.splice(availableSquares.indexOf(lightBishopPos), 1); // Place second bishop on dark square var darkBishopPos = darkSquares[Math.floor(Math.random() * darkSquares.length)]; position[darkBishopPos] = 'B'; availableSquares.splice(availableSquares.indexOf(darkBishopPos), 1); // Step 2: Place queen randomly in remaining squares var queenPos = availableSquares[Math.floor(Math.random() * availableSquares.length)]; position[queenPos] = 'Q'; availableSquares.splice(availableSquares.indexOf(queenPos), 1); // Step 3: Place knights randomly in remaining squares var knight1Pos = availableSquares[Math.floor(Math.random() * availableSquares.length)]; position[knight1Pos] = 'N'; availableSquares.splice(availableSquares.indexOf(knight1Pos), 1); var knight2Pos = availableSquares[Math.floor(Math.random() * availableSquares.length)]; position[knight2Pos] = 'N'; availableSquares.splice(availableSquares.indexOf(knight2Pos), 1); // Step 4: Place king and rooks (king must be between rooks) // Sort remaining squares to ensure proper rook-king-rook placement availableSquares.sort(function (a, b) { return a - b; }); position[availableSquares[0]] = 'R'; // First rook position[availableSquares[1]] = 'K'; // King position[availableSquares[2]] = 'R'; // Second rook // Update board display for (var i = 0; i < 8; i++) { boardSquares[i].setPiece(pieceSymbols[position[i]]); } // Generate position notation currentPosition = position.join(''); updatePositionText(); } function updatePositionText() { if (positionText) { positionText.setText('Position: ' + currentPosition); } } function copyPosition() { // Flash effect to show copy action LK.effects.flashScreen(0x27ae60, 300); } function resetToStandard() { var standardPosition = ['R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R']; for (var i = 0; i < 8; i++) { boardSquares[i].setPiece(pieceSymbols[standardPosition[i]]); } currentPosition = standardPosition.join(''); updatePositionText(); } // Initialize board initializeBoard(); // Create title var titleText = new Text2('Chess960 Position Generator', { size: 60, fill: 0xFFFFFF }); titleText.anchor.set(0.5, 0); titleText.x = 2048 / 2; titleText.y = 100; game.addChild(titleText); // Create subtitle for ranks var rankLabel = new Text2('Ranks 8-7 (Black) and 2-1 (White)', { size: 32, fill: 0xBDC3C7 }); rankLabel.anchor.set(0.5, 1); rankLabel.x = 2048 / 2; rankLabel.y = 380; game.addChild(rankLabel); // Create position display text positionText = new Text2('Position: RNBQKBNR', { size: 48, fill: 0xFFFFFF }); positionText.anchor.set(0.5, 0); positionText.x = 2048 / 2; positionText.y = 1000; game.addChild(positionText); // Create generate button var generateBtn = new GenerateButton(generateChess960Position); generateBtn.x = 2048 / 2; generateBtn.y = 1200; game.addChild(generateBtn); // Create copy button var copyBtn = new ActionButton('Copy Position', 'green', copyPosition); copyBtn.x = 2048 / 2 - 200; copyBtn.y = 1350; game.addChild(copyBtn); // Create reset button var resetBtn = new ActionButton('Standard Setup', 'red', resetToStandard); resetBtn.x = 2048 / 2 + 200; resetBtn.y = 1350; game.addChild(resetBtn); // Create instructions var instructionText = new Text2('Bishops on opposite colors, King between Rooks', { size: 28, fill: 0x95A5A6 }); instructionText.anchor.set(0.5, 0); instructionText.x = 2048 / 2; instructionText.y = 1450; game.addChild(instructionText); // Set initial standard position currentPosition = 'RNBQKBNR'; resetToStandard();
===================================================================
--- original.js
+++ change.js
@@ -104,11 +104,11 @@
function initializeBoard() {
var boardSize = 1600; // 8 squares * 200px each
var startX = (2048 - boardSize) / 2;
var startY = 400;
- // Create 8x8 board (we only show rank 8 for Chess960)
- for (var rank = 0; rank < 2; rank++) {
- // Show ranks 8 and 1
+ // Create 4 ranks: 8, 7, 2, 1 (back ranks + pawn ranks)
+ for (var rank = 0; rank < 4; rank++) {
+ // Show ranks 8, 7, 2, 1
for (var file = 0; file < 8; file++) {
var isLight = (rank + file) % 2 === 0;
var square = new ChessSquare(isLight, file, rank);
square.x = startX + file * 200;
@@ -117,8 +117,17 @@
if (rank === 0) {
// Only store rank 8 squares for piece placement
boardSquares.push(square);
}
+ // Add pawns to rank 7 (black pawns) and rank 2 (white pawns)
+ if (rank === 1) {
+ // Rank 7 - black pawns
+ square.setPiece('♟');
+ }
+ if (rank === 2) {
+ // Rank 2 - white pawns
+ square.setPiece('♙');
+ }
}
}
}
function generateChess960Position() {
@@ -194,9 +203,9 @@
titleText.x = 2048 / 2;
titleText.y = 100;
game.addChild(titleText);
// Create subtitle for ranks
-var rankLabel = new Text2('Rank 8 (White Back Rank)', {
+var rankLabel = new Text2('Ranks 8-7 (Black) and 2-1 (White)', {
size: 32,
fill: 0xBDC3C7
});
rankLabel.anchor.set(0.5, 1);