User prompt
You are a chess AI whose playing strength is based on the number of stars the player invests (maximum 10). Use the following rules: If the player invests 1–3 stars: Play like a beginner. Make simple moves. Occasionally make blunders. Do not calculate deeply. If the player invests 4–7 stars: Play like an intermediate player. Avoid obvious mistakes. Defend your pieces. Play a solid game. If the player invests 8–10 stars: Play like a strong club-level player. Evaluate tactics, think 2–3 moves ahead, and avoid all mistakes. Prioritize king safety, material advantage, and punish bad moves. Always respond with your best legal move in standard algebraic notation (e.g. Nf6, Qxe4+).
User prompt
Oyuncunun yatırdığı yıldız miktarına göre yapay zekanın zorluk seviyesi ayarlanır. Az yıldız yatırılırsa, yapay zeka sadece basit hamleler ve yüzeysel değerlendirme yapar. Orta miktarda yıldız yatırılırsa, temel strateji kullanır ve 1-2 hamle sonrasını hesaplar. Yüksek miktarda yıldız yatırılırsa, daha derin analiz (3+ hamle), taş kazanma önceliği, şah güvenliği ve tuzaklardan kaçınma gibi gelişmiş davranışlar sergiler
User prompt
Satranç oyununda yapay zeka oyuncususun. Geçerli tüm hamleleri değerlendir. Şahın tehdit altındaysa önce onu tehditten kurtarmaya çalış. Eğer şah tehdit altında değilse, en avantajlı hamleleri yapmaya çalış: taş kazan, rakibin önemli taşlarını tehdit et veya aktif pozisyonlar elde et. Ciddi hatalardan kaçın, şahını asla tehdit altında bırakma. Temel oyun kurallarına ve basit değerlendirme ölçütlerine göre en iyi hamleyi yap.
User prompt
Oyuncunun şahı tehdit altındaysa (şah çekilmişse) ve bu tehdidi ortadan kaldırabilecek hiçbir yasal hamle yoksa, durumu 'şah mat' olarak değerlendir. Oyunu bitir, kazananı ilan et ve hamle yapılmasına izin verme.
User prompt
Please fix the bug: 'Uncaught RangeError: Maximum call stack size exceeded' in or related to this line: 'var moves = getValidMoves(piece);' Line Number: 436
User prompt
Eğer mevcut oyuncunun şahı tehdit altındaysa (şah çekilmişse), sadece şahı tehditten kurtaracak hamleler yapılabilsin. Şahı tehditten kurtarmayan hiçbir hamleye izin verme. Eğer şah tehdit altında değilse, şahı başka bir taşın yeme alanına sokacak hamleleri de engelle. Oyuncu hiçbir şekilde şahını tehlikeye atamasın.
User prompt
zorluk derecesi oyunun başında secilebilsin
User prompt
oyunu yapay zekaya karşı oynanacak şekilde yapabilirmisin. yapay zekanın basitten zora doğru 5 derecesi olsun
User prompt
dosyalardaki taş isimlerini Türkçe yazabilir misin
User prompt
oluşturduğun ses dosyalarının adını Türkçe yazabilir misin
User prompt
Oyunda şu olaylar için ses efekti çal: Taş hareket ettiğinde: hareket.mp3 Taş bir rakip taşı yediğinde: yeme.mp3 Şah çekildiğinde: sah.mp3 Rok yapıldığında: rok.mp3 Piyon vezire dönüştüğünde: terfi.mp3 Oyun bittiğinde: bitis.mp3 Ses dosyalarını assets/sounds/ klasörüne koy ve pubspec.yaml dosyasına tanımla. Flutter'da AudioPlayer (örnek: audioplayers paketi) kullanarak bu sesleri çal. Örneğin: dart Kopyala Düzenle final player = AudioPlayer(); await player.play(AssetSource('sounds/hareket.mp3')); Her olayın gerçekleştiği fonksiyona ilgili sesi ekle.
User prompt
Oyunda bir piyon son sıraya ulaştığında (beyaz için 0. satır, siyah için 7. satır), oyuncuya "Vezir", "Kale", "Fil" veya "At" seçeneklerini sunan bir showDialog() göster. Seçilen taşın türü, piyonun yerini alacak şekilde güncellensin. Yeni taş, seçilen türe uygun şekilde davranmalı (hareket kuralları değişmeli). Örnek seçim ekranı şu şekilde olabilir: dart Kopyala Düzenle showDialog( context: context, builder: (BuildContext context) { return AlertDialog( title: Text("Taş Seçin"), content: Column( mainAxisSize: MainAxisSize.min, children: [ ElevatedButton(onPressed: () => Navigator.pop(context, 'vezir'), child: Text("Vezir")), ElevatedButton(onPressed: () => Navigator.pop(context, 'kale'), child: Text("Kale")), ElevatedButton(onPressed: () => Navigator.pop(context, 'fil'), child: Text("Fil")), ElevatedButton(onPressed: () => Navigator.pop(context, 'at'), child: Text("At")), ], ), ); }, ).then((value) { parca.tur = value; // seçilen türü ata // UI ve hareket kuralları buna göre güncellenmeli }); Bu işlemi hareketYap() veya movePiece() fonksiyonunun sonunda tetikle.
User prompt
Oyunda bir piyon son sıraya (beyaz için 0. satır, siyah için 7. satır) ulaştığında piyon vezire dönüşsün. Bu kontrolü hareketYap() fonksiyonunun sonunda yap. Örneğin: dart Kopyala Düzenle if (parca.tur == "piyon" && (parca.satır == 0 || parca.satır == 7)) { parca.tur = "vezir"; // UI ve özellikleri güncelle } İstersen kullanıcıdan seçim alarak "vezir", "kale", "fil" veya "at" seçeneklerini gösteren bir arayüz de açabilirsin (showDialog ile). Ama otomatik vezir yeterli.
User prompt
Flutter ile geliştirdiğim satranç oyununda rok hamlesi yapılamıyor. Oyuna şu kurallara uygun rok hamlesi desteği ekle: Kral ve kale daha önce hiç oynamamışsa, Aradaki kareler boşsa, Kral geçeceği ve varacağı karelerde şahta değilse, o zaman rok yapılabilsin. Rok yapıldığında: Kral 2 kare yana gider Kale onun öbür yanına atlar Bu işlemi getValidMoves() fonksiyonuna ve taş hareketi fonksiyonuna dahil et. Flutter’da kareler board[row][col] gibi 2D dizide tutuluyor.
User prompt
Flutter ile yaptığım satranç oyununda, kullanıcı taşın üzerine doğrudan dokunduğunda taş seçilemiyor. Ancak taşın bulunduğu karenin boş kısmına tıklanırsa çalışıyor. Taş objeleri GestureDetector ile veya benzer şekilde etkileşimli olarak tanımlanmış olabilir. Bunu düzeltmek için: Taşın olduğu alan da GestureDetector kapsamalı. Dokunma olayları doğrudan taşın üstünde de çalışmalı.
User prompt
rakip taşın üzerine basınca onu alsın
User prompt
çok iyi ama rakibinin taşını alırken bir kaç sefer tuşa basmak gerekebiliyor. oyun kuranları içerisinde rakibin taşının bulunduğu karenin herhangi bir yerine tıklayınca taşı alsın.
User prompt
hala olmadı
User prompt
taşın hareket edebileceği alanda rakip oyuncunun taşı varsa o taşı alıp yerine gecebilmeliyiz
User prompt
Satranç oyununda, bir taş rakip renkten başka bir taşın olduğu kareye gidebilirse, o taşı yemeli (yani tahtadan kaldırılmalı). Taş hareketi yapılırken: Hedef karede rakip taş varsa, o taş kaldırılır. Aynı renkten taş varsa, hareket engellenir.
User prompt
taşlar birbirini yiyemiyor bunu düzeltebilirmisin
User prompt
oyundaki yazılar Türkçe olsun
User prompt
taşlar tahtaya tam oturmamış onu düzeltebilirmisin
User prompt
Place chess pieces using standard setup on an 8x8 board. Black main pieces on row 0 Black pawns on row 1 White pawns on row 6 White main pieces on row 7 Arrange each row as: Rook, Knight, Bishop, Queen, King, Bishop, Knight, Rook. Use Dart/Flutter syntax and adjust piece coordinates accordingly.
User prompt
Fix the initial chess piece placement in my app. Use standard chess opening positions on an 8x8 board: White pieces on rows 1 and 2 Black pieces on rows 7 and 8 Arrange them as: Row 1 (White): Rook, Knight, Bishop, Queen, King, Bishop, Knight, Rook Row 2: All pawns Row 7: All black pawns Row 8 (Black): Rook, Knight, Bishop, Queen, King, Bishop, Knight, Rook Make sure the board is indexed properly and each piece is aligned correctly based on its type and color.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var ChessPiece = Container.expand(function (type, color, row, col) {
var self = Container.call(this);
self.pieceType = type;
self.color = color;
self.row = row;
self.col = col;
self.hasMoved = false;
var pieceTypeMap = {
'pawn': color === 'white' ? 'beyazPiyon' : 'siyahPiyon',
'rook': color === 'white' ? 'beyazKale' : 'siyahKale',
'knight': color === 'white' ? 'beyazAt' : 'siyahAt',
'bishop': color === 'white' ? 'beyazFil' : 'siyahFil',
'queen': color === 'white' ? 'beyazVezir' : 'siyahVezir',
'king': color === 'white' ? 'beyazSah' : 'siyahSah'
};
var assetId = pieceTypeMap[type];
var pieceGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function (x, y, obj) {
if (gameState !== 'playing' || isAiTurn) return;
if (currentPlayer === self.color) {
// Select this piece if it belongs to current player
selectedPiece = self;
selectedSquare = {
row: self.row,
col: self.col
};
validMoves = getValidMoves(self);
updateBoardDisplay();
} else if (selectedPiece && isValidMove(selectedPiece.row, selectedPiece.col, self.row, self.col)) {
// If clicking on opponent piece and it's a valid capture move
movePiece(selectedPiece, self.row, self.col);
}
};
return self;
});
var Square = Container.expand(function (row, col, isLight) {
var self = Container.call(this);
self.row = row;
self.col = col;
self.isLight = isLight;
self.piece = null;
var squareGraphics = self.attachAsset(isLight ? 'lightSquare' : 'darkSquare', {
anchorX: 0,
anchorY: 0
});
self.down = function (x, y, obj) {
if (gameState !== 'playing' || isAiTurn) return;
if (selectedPiece && isValidMove(selectedPiece.row, selectedPiece.col, self.row, self.col)) {
movePiece(selectedPiece, self.row, self.col);
} else {
// Check if there's a piece on this square that belongs to current player
var pieceOnSquare = board[self.row][self.col];
if (pieceOnSquare && pieceOnSquare.color === currentPlayer) {
// Select this piece if it belongs to current player
selectedPiece = pieceOnSquare;
selectedSquare = {
row: self.row,
col: self.col
};
validMoves = getValidMoves(pieceOnSquare);
updateBoardDisplay();
} else {
clearSelection();
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1e293b
});
/****
* Game Code
****/
// Game state variables
var gameState = 'betting'; // 'betting', 'playing', 'gameOver'
var currentPlayer = 'white';
var selectedPiece = null;
var selectedSquare = null;
var validMoves = [];
var board = [];
var pieces = [];
// Player data
var playerStars = storage.playerStars || 10;
var opponentStars = storage.opponentStars || 10;
var playerBet = 0;
var opponentBet = 0;
var betPhase = 'playerBetting'; // 'playerBetting', 'opponentBetting', 'waitingForOpponent'
// AI system
var aiDifficulty = storage.aiDifficulty || 1; // 1-5 difficulty levels
var aiThinkingTime = 1000; // Base thinking time in milliseconds
var isAiTurn = false;
// UI elements
var boardContainer = new Container();
var squareOverlays = [];
var starDisplay, betDisplay, gameStatusDisplay;
// Initialize chess board
function initializeBoard() {
board = [];
pieces = [];
// Create 8x8 board
for (var row = 0; row < 8; row++) {
board[row] = [];
for (var col = 0; col < 8; col++) {
board[row][col] = null;
}
}
// Setup initial piece positions - standard chess layout
var backRankSetup = ['rook', 'knight', 'bishop', 'queen', 'king', 'bishop', 'knight', 'rook'];
// Place black pieces (rows 0-1, top of board)
// Row 0: Black back rank
for (var col = 0; col < 8; col++) {
var piece = new ChessPiece(backRankSetup[col], 'black', 0, col);
pieces.push(piece);
board[0][col] = piece;
boardContainer.addChild(piece);
piece.x = col * 225 + 112.5;
piece.y = 0 * 225 + 112.5;
}
// Row 1: Black pawns
for (var col = 0; col < 8; col++) {
var piece = new ChessPiece('pawn', 'black', 1, col);
pieces.push(piece);
board[1][col] = piece;
boardContainer.addChild(piece);
piece.x = col * 225 + 112.5;
piece.y = 1 * 225 + 112.5;
}
// Place white pieces (rows 6-7, bottom of board)
// Row 6: White pawns
for (var col = 0; col < 8; col++) {
var piece = new ChessPiece('pawn', 'white', 6, col);
pieces.push(piece);
board[6][col] = piece;
boardContainer.addChild(piece);
piece.x = col * 225 + 112.5;
piece.y = 6 * 225 + 112.5;
}
// Row 7: White back rank
for (var col = 0; col < 8; col++) {
var piece = new ChessPiece(backRankSetup[col], 'white', 7, col);
pieces.push(piece);
board[7][col] = piece;
boardContainer.addChild(piece);
piece.x = col * 225 + 112.5;
piece.y = 7 * 225 + 112.5;
}
}
// Create visual board squares
function createBoardDisplay() {
boardContainer.x = 124;
boardContainer.y = 466;
game.addChild(boardContainer);
// Create board background
var boardBg = boardContainer.attachAsset('chessBoard', {
anchorX: 0,
anchorY: 0
});
// Create squares
for (var row = 0; row < 8; row++) {
squareOverlays[row] = [];
for (var col = 0; col < 8; col++) {
var isLight = (row + col) % 2 === 0;
var square = new Square(row, col, isLight);
square.x = col * 225;
square.y = row * 225;
boardContainer.addChild(square);
squareOverlays[row][col] = square;
}
}
}
// Get valid moves for a piece
function getValidMoves(piece) {
var moves = [];
if (piece.pieceType === 'pawn') {
var direction = piece.color === 'white' ? -1 : 1;
var startRow = piece.color === 'white' ? 6 : 1;
// Forward move
if (isValidSquare(piece.row + direction, piece.col) && !board[piece.row + direction][piece.col]) {
moves.push({
row: piece.row + direction,
col: piece.col
});
// Double move from start
if (piece.row === startRow && !board[piece.row + 2 * direction][piece.col]) {
moves.push({
row: piece.row + 2 * direction,
col: piece.col
});
}
}
// Captures
for (var dc = -1; dc <= 1; dc += 2) {
var newRow = piece.row + direction;
var newCol = piece.col + dc;
if (isValidSquare(newRow, newCol) && board[newRow][newCol] && board[newRow][newCol].color !== piece.color) {
moves.push({
row: newRow,
col: newCol
});
}
}
} else if (piece.pieceType === 'rook') {
// Horizontal and vertical moves
var directions = [[0, 1], [0, -1], [1, 0], [-1, 0]];
for (var d = 0; d < directions.length; d++) {
var dir = directions[d];
for (var i = 1; i < 8; i++) {
var newRow = piece.row + dir[0] * i;
var newCol = piece.col + dir[1] * i;
if (!isValidSquare(newRow, newCol)) break;
var targetPiece = board[newRow][newCol];
if (!targetPiece) {
moves.push({
row: newRow,
col: newCol
});
} else {
if (targetPiece.color !== piece.color) {
moves.push({
row: newRow,
col: newCol
});
}
break;
}
}
}
} else if (piece.pieceType === 'bishop') {
// Diagonal moves
var directions = [[1, 1], [1, -1], [-1, 1], [-1, -1]];
for (var d = 0; d < directions.length; d++) {
var dir = directions[d];
for (var i = 1; i < 8; i++) {
var newRow = piece.row + dir[0] * i;
var newCol = piece.col + dir[1] * i;
if (!isValidSquare(newRow, newCol)) break;
var targetPiece = board[newRow][newCol];
if (!targetPiece) {
moves.push({
row: newRow,
col: newCol
});
} else {
if (targetPiece.color !== piece.color) {
moves.push({
row: newRow,
col: newCol
});
}
break;
}
}
}
} else if (piece.pieceType === 'queen') {
// Combination of rook and bishop moves
var directions = [[0, 1], [0, -1], [1, 0], [-1, 0], [1, 1], [1, -1], [-1, 1], [-1, -1]];
for (var d = 0; d < directions.length; d++) {
var dir = directions[d];
for (var i = 1; i < 8; i++) {
var newRow = piece.row + dir[0] * i;
var newCol = piece.col + dir[1] * i;
if (!isValidSquare(newRow, newCol)) break;
var targetPiece = board[newRow][newCol];
if (!targetPiece) {
moves.push({
row: newRow,
col: newCol
});
} else {
if (targetPiece.color !== piece.color) {
moves.push({
row: newRow,
col: newCol
});
}
break;
}
}
}
} else if (piece.pieceType === 'king') {
// One square in any direction
var directions = [[0, 1], [0, -1], [1, 0], [-1, 0], [1, 1], [1, -1], [-1, 1], [-1, -1]];
for (var d = 0; d < directions.length; d++) {
var dir = directions[d];
var newRow = piece.row + dir[0];
var newCol = piece.col + dir[1];
if (isValidSquare(newRow, newCol)) {
var targetPiece = board[newRow][newCol];
if (!targetPiece || targetPiece.color !== piece.color) {
moves.push({
row: newRow,
col: newCol
});
}
}
}
// Castling moves
if (!piece.hasMoved) {
var kingRow = piece.row;
// Kingside castling (short castling)
var kingsideRook = board[kingRow][7];
if (kingsideRook && kingsideRook.pieceType === 'rook' && kingsideRook.color === piece.color && !kingsideRook.hasMoved) {
// Check if squares between king and rook are empty
if (!board[kingRow][5] && !board[kingRow][6]) {
// For now, add the move (should also check if king passes through check)
moves.push({
row: kingRow,
col: 6,
isCastling: true,
castlingType: 'kingside'
});
}
}
// Queenside castling (long castling)
var queensideRook = board[kingRow][0];
if (queensideRook && queensideRook.pieceType === 'rook' && queensideRook.color === piece.color && !queensideRook.hasMoved) {
// Check if squares between king and rook are empty
if (!board[kingRow][1] && !board[kingRow][2] && !board[kingRow][3]) {
// For now, add the move (should also check if king passes through check)
moves.push({
row: kingRow,
col: 2,
isCastling: true,
castlingType: 'queenside'
});
}
}
}
} else if (piece.pieceType === 'knight') {
// L-shaped moves
var knightMoves = [[2, 1], [2, -1], [-2, 1], [-2, -1], [1, 2], [1, -2], [-1, 2], [-1, -2]];
for (var m = 0; m < knightMoves.length; m++) {
var move = knightMoves[m];
var newRow = piece.row + move[0];
var newCol = piece.col + move[1];
if (isValidSquare(newRow, newCol)) {
var targetPiece = board[newRow][newCol];
if (!targetPiece || targetPiece.color !== piece.color) {
moves.push({
row: newRow,
col: newCol
});
}
}
}
}
return moves;
}
function isValidSquare(row, col) {
return row >= 0 && row < 8 && col >= 0 && col < 8;
}
function isInCheck(playerColor) {
// Find the king of the specified color
var king = null;
for (var i = 0; i < pieces.length; i++) {
if (pieces[i].pieceType === 'king' && pieces[i].color === playerColor) {
king = pieces[i];
break;
}
}
if (!king) return false;
// Check if any opponent piece can attack the king
for (var i = 0; i < pieces.length; i++) {
var piece = pieces[i];
if (piece.color !== playerColor) {
var moves = getValidMoves(piece);
for (var j = 0; j < moves.length; j++) {
if (moves[j].row === king.row && moves[j].col === king.col) {
return true;
}
}
}
}
return false;
}
function isValidMove(fromRow, fromCol, toRow, toCol) {
for (var i = 0; i < validMoves.length; i++) {
if (validMoves[i].row === toRow && validMoves[i].col === toCol) {
return true;
}
}
return false;
}
function movePiece(piece, newRow, newCol) {
// Check if this is a castling move
var isCastlingMove = false;
var castlingType = '';
if (piece.pieceType === 'king' && !piece.hasMoved && Math.abs(newCol - piece.col) === 2) {
isCastlingMove = true;
castlingType = newCol > piece.col ? 'kingside' : 'queenside';
}
var capturedPiece = board[newRow][newCol];
// Handle capture first (before moving the piece)
if (capturedPiece && capturedPiece.color !== piece.color) {
// Remove captured piece from pieces array
for (var i = pieces.length - 1; i >= 0; i--) {
if (pieces[i] === capturedPiece) {
pieces.splice(i, 1);
break;
}
}
// Remove captured piece from board container
if (capturedPiece.parent) {
capturedPiece.parent.removeChild(capturedPiece);
}
// Destroy the visual representation
capturedPiece.destroy();
LK.getSound('yeme').play();
} else {
LK.getSound('hareket').play();
}
// Remove piece from old position on board
board[piece.row][piece.col] = null;
// Update piece position data
piece.row = newRow;
piece.col = newCol;
piece.hasMoved = true;
// Place piece in new position on board
board[newRow][newCol] = piece;
// Handle castling - move the rook
if (isCastlingMove) {
LK.getSound('rok').play();
var rookOldCol, rookNewCol;
if (castlingType === 'kingside') {
rookOldCol = 7;
rookNewCol = 5;
} else {
// queenside
rookOldCol = 0;
rookNewCol = 3;
}
var rook = board[newRow][rookOldCol];
if (rook) {
// Remove rook from old position
board[newRow][rookOldCol] = null;
// Update rook position
rook.row = newRow;
rook.col = rookNewCol;
rook.hasMoved = true;
// Place rook in new position
board[newRow][rookNewCol] = rook;
// Animate rook movement
tween(rook, {
x: rookNewCol * 225 + 112.5,
y: newRow * 225 + 112.5
}, {
duration: 300,
easing: tween.easeOut
});
}
}
// Animate piece movement
tween(piece, {
x: newCol * 225 + 112.5,
y: newRow * 225 + 112.5
}, {
duration: 300,
easing: tween.easeOut
});
// Clear selection
clearSelection();
// Switch turns
currentPlayer = currentPlayer === 'white' ? 'black' : 'white';
// Check if the current player is in check
if (isInCheck(currentPlayer)) {
LK.getSound('sah').play();
}
updateGameStatus();
// Check for pawn promotion
if (piece.pieceType === 'pawn' && (piece.row === 0 || piece.row === 7)) {
LK.getSound('terfi').play();
if (piece.color === 'black') {
// AI auto-promotes to queen
promotePiece(piece, 'queen');
} else {
showPromotionDialog(piece);
}
}
// Check for game over conditions
checkGameOver();
// Trigger AI move if it's AI's turn
if (currentPlayer === 'black' && gameState === 'playing') {
makeAIMove();
}
}
function clearSelection() {
selectedPiece = null;
selectedSquare = null;
validMoves = [];
updateBoardDisplay();
}
function updateBoardDisplay() {
// Clear all overlays
for (var row = 0; row < 8; row++) {
for (var col = 0; col < 8; col++) {
var square = squareOverlays[row][col];
square.removeChildren();
var isLight = (row + col) % 2 === 0;
var squareGraphics = square.attachAsset(isLight ? 'lightSquare' : 'darkSquare', {
anchorX: 0,
anchorY: 0
});
}
}
// Show selected square
if (selectedSquare) {
var selectedSquareOverlay = squareOverlays[selectedSquare.row][selectedSquare.col];
selectedSquareOverlay.removeChildren();
var selectedGraphics = selectedSquareOverlay.attachAsset('selectedSquare', {
anchorX: 0,
anchorY: 0
});
}
// Show valid moves
for (var i = 0; i < validMoves.length; i++) {
var move = validMoves[i];
var moveSquare = squareOverlays[move.row][move.col];
moveSquare.removeChildren();
var moveGraphics = moveSquare.attachAsset('validMoveSquare', {
anchorX: 0,
anchorY: 0
});
}
}
function checkGameOver() {
// Simple game over check - if king is captured
var whiteKingExists = false;
var blackKingExists = false;
for (var i = 0; i < pieces.length; i++) {
var piece = pieces[i];
if (piece.pieceType === 'king') {
if (piece.color === 'white') whiteKingExists = true;
if (piece.color === 'black') blackKingExists = true;
}
}
if (!whiteKingExists) {
endGame('black');
} else if (!blackKingExists) {
endGame('white');
}
}
function endGame(winner) {
gameState = 'gameOver';
LK.getSound('bitis').play();
// Award stars
if (winner === 'white') {
playerStars += opponentBet;
opponentStars -= opponentBet;
} else {
playerStars -= playerBet;
opponentStars += playerBet;
}
// Save to storage
storage.playerStars = playerStars;
storage.opponentStars = opponentStars;
updateStarDisplay();
if (winner === 'white') {
LK.showYouWin();
} else {
LK.showGameOver();
}
}
function createUI() {
// Star display
starDisplay = new Text2('Yıldızlar: ' + playerStars, {
size: 60,
fill: 0xFFFFFF
});
starDisplay.anchor.set(0.5, 0);
LK.gui.top.addChild(starDisplay);
starDisplay.y = 100;
// Game status display
gameStatusDisplay = new Text2('Bahis yapın!', {
size: 50,
fill: 0xFFFFFF
});
gameStatusDisplay.anchor.set(0.5, 0);
LK.gui.top.addChild(gameStatusDisplay);
gameStatusDisplay.y = 180;
// Betting interface
createBettingUI();
}
function createBettingUI() {
// AI Difficulty selection
var difficultyDisplay = new Text2('AI Zorluğu: ' + aiDifficulty, {
size: 45,
fill: 0xFFFFFF
});
difficultyDisplay.anchor.set(0.5, 1);
LK.gui.bottom.addChild(difficultyDisplay);
difficultyDisplay.y = -280;
// AI difficulty buttons
var decreaseDiffBtn = LK.getAsset('betButton', {
anchorX: 0.5,
anchorY: 0.5
});
var increaseDiffBtn = LK.getAsset('betButton', {
anchorX: 0.5,
anchorY: 0.5
});
decreaseDiffBtn.width = 150;
decreaseDiffBtn.height = 60;
increaseDiffBtn.width = 150;
increaseDiffBtn.height = 60;
LK.gui.bottom.addChild(decreaseDiffBtn);
LK.gui.bottom.addChild(increaseDiffBtn);
decreaseDiffBtn.x = -100;
decreaseDiffBtn.y = -230;
increaseDiffBtn.x = 100;
increaseDiffBtn.y = -230;
var decreaseDiffText = new Text2('-', {
size: 30,
fill: 0xFFFFFF
});
decreaseDiffText.anchor.set(0.5, 0.5);
decreaseDiffBtn.addChild(decreaseDiffText);
var increaseDiffText = new Text2('+', {
size: 30,
fill: 0xFFFFFF
});
increaseDiffText.anchor.set(0.5, 0.5);
increaseDiffBtn.addChild(increaseDiffText);
decreaseDiffBtn.down = function () {
if (aiDifficulty > 1) {
aiDifficulty--;
storage.aiDifficulty = aiDifficulty;
difficultyDisplay.setText('AI Zorluğu: ' + aiDifficulty);
}
};
increaseDiffBtn.down = function () {
if (aiDifficulty < 5) {
aiDifficulty++;
storage.aiDifficulty = aiDifficulty;
difficultyDisplay.setText('AI Zorluğu: ' + aiDifficulty);
}
};
// Bet amount display
betDisplay = new Text2('Bahis: ' + playerBet + ' yıldız', {
size: 50,
fill: 0xFFFFFF
});
betDisplay.anchor.set(0.5, 1);
LK.gui.bottom.addChild(betDisplay);
betDisplay.y = -200;
// Bet buttons
var decreaseBetBtn = LK.getAsset('betButton', {
anchorX: 0.5,
anchorY: 0.5
});
var increaseBetBtn = LK.getAsset('betButton', {
anchorX: 0.5,
anchorY: 0.5
});
var confirmBetBtn = LK.getAsset('betButton', {
anchorX: 0.5,
anchorY: 0.5
});
LK.gui.bottom.addChild(decreaseBetBtn);
LK.gui.bottom.addChild(increaseBetBtn);
LK.gui.bottom.addChild(confirmBetBtn);
decreaseBetBtn.x = -200;
decreaseBetBtn.y = -100;
increaseBetBtn.x = 0;
increaseBetBtn.y = -100;
confirmBetBtn.x = 200;
confirmBetBtn.y = -100;
var decreaseText = new Text2('-', {
size: 40,
fill: 0xFFFFFF
});
decreaseText.anchor.set(0.5, 0.5);
decreaseBetBtn.addChild(decreaseText);
var increaseText = new Text2('+', {
size: 40,
fill: 0xFFFFFF
});
increaseText.anchor.set(0.5, 0.5);
increaseBetBtn.addChild(increaseText);
var confirmText = new Text2('Onayla', {
size: 30,
fill: 0xFFFFFF
});
confirmText.anchor.set(0.5, 0.5);
confirmBetBtn.addChild(confirmText);
// Button interactions
decreaseBetBtn.down = function () {
if (playerBet > 0) {
playerBet--;
updateBetDisplay();
}
};
increaseBetBtn.down = function () {
if (playerBet < playerStars) {
playerBet++;
updateBetDisplay();
}
};
confirmBetBtn.down = function () {
if (gameState === 'betting') {
confirmBet();
}
};
}
function updateBetDisplay() {
betDisplay.setText('Bahis: ' + playerBet + ' yıldız');
}
function updateStarDisplay() {
starDisplay.setText('Yıldızlar: ' + playerStars);
}
function updateGameStatus() {
if (gameState === 'betting') {
gameStatusDisplay.setText('Bahis yapın! (AI Seviye: ' + aiDifficulty + ')');
} else if (gameState === 'playing') {
if (isAiTurn) {
gameStatusDisplay.setText('AI düşünüyor...');
} else {
var playerName = currentPlayer === 'white' ? 'Siz' : 'AI';
gameStatusDisplay.setText(playerName + ' sırası');
}
}
}
function confirmBet() {
// For now, simulate opponent bet (random between 0 and their stars)
opponentBet = Math.floor(Math.random() * (Math.min(opponentStars, 10) + 1));
gameState = 'playing';
updateGameStatus();
// Hide betting UI
LK.gui.bottom.removeChildren();
// Show bet results
var betResultText = new Text2('Sizin bahis: ' + playerBet + ' | Rakip bahis: ' + opponentBet, {
size: 40,
fill: 0xFFFFFF
});
betResultText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(betResultText);
betResultText.y = -50;
}
function showPromotionDialog(piece) {
// Create dialog background
var dialogBg = LK.getAsset('chessBoard', {
anchorX: 0.5,
anchorY: 0.5
});
dialogBg.x = 1024;
dialogBg.y = 1366;
dialogBg.width = 800;
dialogBg.height = 600;
dialogBg.tint = 0x444444;
game.addChild(dialogBg);
// Dialog title
var titleText = new Text2('Taş Seçin', {
size: 60,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 1200;
game.addChild(titleText);
// Promotion options
var promotionOptions = ['queen', 'rook', 'bishop', 'knight'];
var optionNames = ['Vezir', 'Kale', 'Fil', 'At'];
var buttons = [];
for (var i = 0; i < promotionOptions.length; i++) {
var button = LK.getAsset('betButton', {
anchorX: 0.5,
anchorY: 0.5
});
button.x = 1024;
button.y = 1300 + i * 100;
button.width = 300;
button.height = 80;
game.addChild(button);
var buttonText = new Text2(optionNames[i], {
size: 40,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
buttonText.x = 1024;
buttonText.y = 1300 + i * 100;
game.addChild(buttonText);
// Store piece type for this button
button.pieceType = promotionOptions[i];
button.dialogElements = [dialogBg, titleText, buttonText];
// Add all buttons to cleanup list
for (var j = 0; j < buttons.length; j++) {
button.dialogElements.push(buttons[j]);
button.dialogElements.push(buttons[j].textElement);
}
button.down = function () {
// Promote the piece
promotePiece(piece, this.pieceType);
// Clean up dialog
for (var k = 0; k < this.dialogElements.length; k++) {
if (this.dialogElements[k].parent) {
this.dialogElements[k].parent.removeChild(this.dialogElements[k]);
}
this.dialogElements[k].destroy();
}
// Clean up remaining buttons
for (var l = 0; l < buttons.length; l++) {
if (buttons[l].parent) {
buttons[l].parent.removeChild(buttons[l]);
}
if (buttons[l].textElement && buttons[l].textElement.parent) {
buttons[l].textElement.parent.removeChild(buttons[l].textElement);
}
buttons[l].destroy();
if (buttons[l].textElement) {
buttons[l].textElement.destroy();
}
}
};
button.textElement = buttonText;
buttons.push(button);
}
}
function promotePiece(piece, newType) {
// Update piece type
piece.pieceType = newType;
// Update the visual representation
piece.removeChildren();
var pieceTypeMap = {
'pawn': piece.color === 'white' ? 'beyazPiyon' : 'siyahPiyon',
'rook': piece.color === 'white' ? 'beyazKale' : 'siyahKale',
'knight': piece.color === 'white' ? 'beyazAt' : 'siyahAt',
'bishop': piece.color === 'white' ? 'beyazFil' : 'siyahFil',
'queen': piece.color === 'white' ? 'beyazVezir' : 'siyahVezir',
'king': piece.color === 'white' ? 'beyazSah' : 'siyahSah'
};
var assetId = pieceTypeMap[newType];
var pieceGraphics = piece.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
}
// AI Functions
function getPieceValue(pieceType) {
var values = {
'pawn': 1,
'knight': 3,
'bishop': 3,
'rook': 5,
'queen': 9,
'king': 1000
};
return values[pieceType] || 0;
}
function evaluatePosition() {
var score = 0;
for (var i = 0; i < pieces.length; i++) {
var piece = pieces[i];
var value = getPieceValue(piece.pieceType);
if (piece.color === 'black') {
score += value;
} else {
score -= value;
}
}
return score;
}
function getAllPossibleMoves(color) {
var allMoves = [];
for (var i = 0; i < pieces.length; i++) {
var piece = pieces[i];
if (piece.color === color) {
var moves = getValidMoves(piece);
for (var j = 0; j < moves.length; j++) {
allMoves.push({
piece: piece,
move: moves[j],
fromRow: piece.row,
fromCol: piece.col,
toRow: moves[j].row,
toCol: moves[j].col
});
}
}
}
return allMoves;
}
function makeAIMove() {
if (currentPlayer !== 'black' || gameState !== 'playing') return;
isAiTurn = true;
var thinkingTime = aiThinkingTime / aiDifficulty;
LK.setTimeout(function () {
var bestMove = selectBestMove();
if (bestMove) {
// Simulate the move
movePiece(bestMove.piece, bestMove.toRow, bestMove.toCol);
}
isAiTurn = false;
}, thinkingTime);
}
function selectBestMove() {
var possibleMoves = getAllPossibleMoves('black');
if (possibleMoves.length === 0) return null;
var bestMove = null;
var bestScore = -Infinity;
// Difficulty 1: Random moves
if (aiDifficulty === 1) {
return possibleMoves[Math.floor(Math.random() * possibleMoves.length)];
}
// Difficulty 2-5: Evaluate moves with increasing depth
for (var i = 0; i < possibleMoves.length; i++) {
var move = possibleMoves[i];
var score = evaluateMove(move);
// Add some randomness for lower difficulties
if (aiDifficulty < 5) {
score += (Math.random() - 0.5) * (6 - aiDifficulty) * 2;
}
if (score > bestScore) {
bestScore = score;
bestMove = move;
}
}
return bestMove;
}
function evaluateMove(move) {
var score = 0;
var targetPiece = board[move.toRow][move.toCol];
// Capture bonus
if (targetPiece && targetPiece.color !== move.piece.color) {
score += getPieceValue(targetPiece.pieceType) * 10;
}
// Position bonuses based on difficulty
if (aiDifficulty >= 3) {
// Control center squares
if (move.toRow >= 3 && move.toRow <= 4 && move.toCol >= 3 && move.toCol <= 4) {
score += 2;
}
// Pawn advancement
if (move.piece.pieceType === 'pawn') {
score += (7 - move.toRow) * 0.5;
}
}
if (aiDifficulty >= 4) {
// King safety - avoid moving king early
if (move.piece.pieceType === 'king' && !move.piece.hasMoved) {
score -= 5;
}
// Develop pieces (knights and bishops)
if ((move.piece.pieceType === 'knight' || move.piece.pieceType === 'bishop') && move.fromRow === 0) {
score += 3;
}
}
if (aiDifficulty === 5) {
// Advanced tactics - protect pieces
var isProtected = false;
for (var i = 0; i < pieces.length; i++) {
if (pieces[i].color === 'black' && pieces[i] !== move.piece) {
var protectMoves = getValidMoves(pieces[i]);
for (var j = 0; j < protectMoves.length; j++) {
if (protectMoves[j].row === move.toRow && protectMoves[j].col === move.toCol) {
isProtected = true;
break;
}
}
}
}
if (isProtected) score += 1;
}
return score;
}
// Initialize everything
createBoardDisplay();
initializeBoard();
createUI();
updateBoardDisplay();
game.update = function () {
// Prevent player input during AI turn
if (isAiTurn) {
// Visual indicator that AI is thinking
if (LK.ticks % 30 === 0) {
var thinkingText = 'AI düşünüyor';
for (var i = 0; i < Math.floor(LK.ticks / 30) % 4; i++) {
thinkingText += '.';
}
gameStatusDisplay.setText(thinkingText);
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -27,9 +27,9 @@
anchorX: 0.5,
anchorY: 0.5
});
self.down = function (x, y, obj) {
- if (gameState !== 'playing') return;
+ if (gameState !== 'playing' || isAiTurn) return;
if (currentPlayer === self.color) {
// Select this piece if it belongs to current player
selectedPiece = self;
selectedSquare = {
@@ -55,9 +55,9 @@
anchorX: 0,
anchorY: 0
});
self.down = function (x, y, obj) {
- if (gameState !== 'playing') return;
+ if (gameState !== 'playing' || isAiTurn) return;
if (selectedPiece && isValidMove(selectedPiece.row, selectedPiece.col, self.row, self.col)) {
movePiece(selectedPiece, self.row, self.col);
} else {
// Check if there's a piece on this square that belongs to current player
@@ -102,8 +102,12 @@
var opponentStars = storage.opponentStars || 10;
var playerBet = 0;
var opponentBet = 0;
var betPhase = 'playerBetting'; // 'playerBetting', 'opponentBetting', 'waitingForOpponent'
+// AI system
+var aiDifficulty = storage.aiDifficulty || 1; // 1-5 difficulty levels
+var aiThinkingTime = 1000; // Base thinking time in milliseconds
+var isAiTurn = false;
// UI elements
var boardContainer = new Container();
var squareOverlays = [];
var starDisplay, betDisplay, gameStatusDisplay;
@@ -482,12 +486,21 @@
updateGameStatus();
// Check for pawn promotion
if (piece.pieceType === 'pawn' && (piece.row === 0 || piece.row === 7)) {
LK.getSound('terfi').play();
- showPromotionDialog(piece);
+ if (piece.color === 'black') {
+ // AI auto-promotes to queen
+ promotePiece(piece, 'queen');
+ } else {
+ showPromotionDialog(piece);
+ }
}
// Check for game over conditions
checkGameOver();
+ // Trigger AI move if it's AI's turn
+ if (currentPlayer === 'black' && gameState === 'playing') {
+ makeAIMove();
+ }
}
function clearSelection() {
selectedPiece = null;
selectedSquare = null;
@@ -585,8 +598,61 @@
// Betting interface
createBettingUI();
}
function createBettingUI() {
+ // AI Difficulty selection
+ var difficultyDisplay = new Text2('AI Zorluğu: ' + aiDifficulty, {
+ size: 45,
+ fill: 0xFFFFFF
+ });
+ difficultyDisplay.anchor.set(0.5, 1);
+ LK.gui.bottom.addChild(difficultyDisplay);
+ difficultyDisplay.y = -280;
+ // AI difficulty buttons
+ var decreaseDiffBtn = LK.getAsset('betButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var increaseDiffBtn = LK.getAsset('betButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ decreaseDiffBtn.width = 150;
+ decreaseDiffBtn.height = 60;
+ increaseDiffBtn.width = 150;
+ increaseDiffBtn.height = 60;
+ LK.gui.bottom.addChild(decreaseDiffBtn);
+ LK.gui.bottom.addChild(increaseDiffBtn);
+ decreaseDiffBtn.x = -100;
+ decreaseDiffBtn.y = -230;
+ increaseDiffBtn.x = 100;
+ increaseDiffBtn.y = -230;
+ var decreaseDiffText = new Text2('-', {
+ size: 30,
+ fill: 0xFFFFFF
+ });
+ decreaseDiffText.anchor.set(0.5, 0.5);
+ decreaseDiffBtn.addChild(decreaseDiffText);
+ var increaseDiffText = new Text2('+', {
+ size: 30,
+ fill: 0xFFFFFF
+ });
+ increaseDiffText.anchor.set(0.5, 0.5);
+ increaseDiffBtn.addChild(increaseDiffText);
+ decreaseDiffBtn.down = function () {
+ if (aiDifficulty > 1) {
+ aiDifficulty--;
+ storage.aiDifficulty = aiDifficulty;
+ difficultyDisplay.setText('AI Zorluğu: ' + aiDifficulty);
+ }
+ };
+ increaseDiffBtn.down = function () {
+ if (aiDifficulty < 5) {
+ aiDifficulty++;
+ storage.aiDifficulty = aiDifficulty;
+ difficultyDisplay.setText('AI Zorluğu: ' + aiDifficulty);
+ }
+ };
// Bet amount display
betDisplay = new Text2('Bahis: ' + playerBet + ' yıldız', {
size: 50,
fill: 0xFFFFFF
@@ -660,12 +726,16 @@
starDisplay.setText('Yıldızlar: ' + playerStars);
}
function updateGameStatus() {
if (gameState === 'betting') {
- gameStatusDisplay.setText('Bahis yapın!');
+ gameStatusDisplay.setText('Bahis yapın! (AI Seviye: ' + aiDifficulty + ')');
} else if (gameState === 'playing') {
- var playerName = currentPlayer === 'white' ? 'Beyaz' : 'Siyah';
- gameStatusDisplay.setText(playerName + ' sırası');
+ if (isAiTurn) {
+ gameStatusDisplay.setText('AI düşünüyor...');
+ } else {
+ var playerName = currentPlayer === 'white' ? 'Siz' : 'AI';
+ gameStatusDisplay.setText(playerName + ' sırası');
+ }
}
}
function confirmBet() {
// For now, simulate opponent bet (random between 0 and their stars)
@@ -780,12 +850,150 @@
anchorX: 0.5,
anchorY: 0.5
});
}
+// AI Functions
+function getPieceValue(pieceType) {
+ var values = {
+ 'pawn': 1,
+ 'knight': 3,
+ 'bishop': 3,
+ 'rook': 5,
+ 'queen': 9,
+ 'king': 1000
+ };
+ return values[pieceType] || 0;
+}
+function evaluatePosition() {
+ var score = 0;
+ for (var i = 0; i < pieces.length; i++) {
+ var piece = pieces[i];
+ var value = getPieceValue(piece.pieceType);
+ if (piece.color === 'black') {
+ score += value;
+ } else {
+ score -= value;
+ }
+ }
+ return score;
+}
+function getAllPossibleMoves(color) {
+ var allMoves = [];
+ for (var i = 0; i < pieces.length; i++) {
+ var piece = pieces[i];
+ if (piece.color === color) {
+ var moves = getValidMoves(piece);
+ for (var j = 0; j < moves.length; j++) {
+ allMoves.push({
+ piece: piece,
+ move: moves[j],
+ fromRow: piece.row,
+ fromCol: piece.col,
+ toRow: moves[j].row,
+ toCol: moves[j].col
+ });
+ }
+ }
+ }
+ return allMoves;
+}
+function makeAIMove() {
+ if (currentPlayer !== 'black' || gameState !== 'playing') return;
+ isAiTurn = true;
+ var thinkingTime = aiThinkingTime / aiDifficulty;
+ LK.setTimeout(function () {
+ var bestMove = selectBestMove();
+ if (bestMove) {
+ // Simulate the move
+ movePiece(bestMove.piece, bestMove.toRow, bestMove.toCol);
+ }
+ isAiTurn = false;
+ }, thinkingTime);
+}
+function selectBestMove() {
+ var possibleMoves = getAllPossibleMoves('black');
+ if (possibleMoves.length === 0) return null;
+ var bestMove = null;
+ var bestScore = -Infinity;
+ // Difficulty 1: Random moves
+ if (aiDifficulty === 1) {
+ return possibleMoves[Math.floor(Math.random() * possibleMoves.length)];
+ }
+ // Difficulty 2-5: Evaluate moves with increasing depth
+ for (var i = 0; i < possibleMoves.length; i++) {
+ var move = possibleMoves[i];
+ var score = evaluateMove(move);
+ // Add some randomness for lower difficulties
+ if (aiDifficulty < 5) {
+ score += (Math.random() - 0.5) * (6 - aiDifficulty) * 2;
+ }
+ if (score > bestScore) {
+ bestScore = score;
+ bestMove = move;
+ }
+ }
+ return bestMove;
+}
+function evaluateMove(move) {
+ var score = 0;
+ var targetPiece = board[move.toRow][move.toCol];
+ // Capture bonus
+ if (targetPiece && targetPiece.color !== move.piece.color) {
+ score += getPieceValue(targetPiece.pieceType) * 10;
+ }
+ // Position bonuses based on difficulty
+ if (aiDifficulty >= 3) {
+ // Control center squares
+ if (move.toRow >= 3 && move.toRow <= 4 && move.toCol >= 3 && move.toCol <= 4) {
+ score += 2;
+ }
+ // Pawn advancement
+ if (move.piece.pieceType === 'pawn') {
+ score += (7 - move.toRow) * 0.5;
+ }
+ }
+ if (aiDifficulty >= 4) {
+ // King safety - avoid moving king early
+ if (move.piece.pieceType === 'king' && !move.piece.hasMoved) {
+ score -= 5;
+ }
+ // Develop pieces (knights and bishops)
+ if ((move.piece.pieceType === 'knight' || move.piece.pieceType === 'bishop') && move.fromRow === 0) {
+ score += 3;
+ }
+ }
+ if (aiDifficulty === 5) {
+ // Advanced tactics - protect pieces
+ var isProtected = false;
+ for (var i = 0; i < pieces.length; i++) {
+ if (pieces[i].color === 'black' && pieces[i] !== move.piece) {
+ var protectMoves = getValidMoves(pieces[i]);
+ for (var j = 0; j < protectMoves.length; j++) {
+ if (protectMoves[j].row === move.toRow && protectMoves[j].col === move.toCol) {
+ isProtected = true;
+ break;
+ }
+ }
+ }
+ }
+ if (isProtected) score += 1;
+ }
+ return score;
+}
// Initialize everything
createBoardDisplay();
initializeBoard();
createUI();
updateBoardDisplay();
game.update = function () {
- // Game loop - handle any continuous updates if needed
+ // Prevent player input during AI turn
+ if (isAiTurn) {
+ // Visual indicator that AI is thinking
+ if (LK.ticks % 30 === 0) {
+ var thinkingText = 'AI düşünüyor';
+ for (var i = 0; i < Math.floor(LK.ticks / 30) % 4; i++) {
+ thinkingText += '.';
+ }
+ gameStatusDisplay.setText(thinkingText);
+ }
+ }
};
\ No newline at end of file