La promotion d'un pion.

Résolu/Fermé
Max747 Messages postés 258 Date d'inscription vendredi 11 juillet 2014 Statut Membre Dernière intervention 11 janvier 2024 - 11 oct. 2022 à 12:21
Max747 Messages postés 258 Date d'inscription vendredi 11 juillet 2014 Statut Membre Dernière intervention 11 janvier 2024 - 11 oct. 2022 à 15:33

Bonjour,

A la création d'une partie d'échecs, avant qu'un seul coup ne soit jouer voici le message qui apparaît:

Warning: Trying to access array offset on value of type null in /customers/6/0/9/jeuxechecs.fr/httpd.www/echecs/chess.php on line 236 Warning: Trying to access array offset on value of type null in /customers/6/0/9/jeuxechecs.fr/httpd.www/echecs/chess.php on line 236
 

Voici le fichier chess.php produisant ce message:

<?php
// set the session cookie parameters so the cookie is only valid for this game - définissez les paramètres du cookie de session afin que le cookie ne soit valide que pour ce jeu.
$parts = pathinfo($_SERVER['REQUEST_URI']);
$path = $parts['dirname'];
if (empty($parts['extension'])) {
	$path .= '/'.$parts['jeuxechecs_fr'];
}
$path = str_replace('\\', '/', $path).'/';
@session_set_cookie_params(0, $path);
//@session_set_cookie_params(time()+365*24*3600, $path);
//session_set_cookie_params(0, $path);
//La valeur de 0 signifie : "Jusqu'à ce que le navigateur soit éteint". $path =/echecs/
//Impossible de modifier les paramètres des cookies de session lorsque la session est active dans /customers/6/0/9/jeuxechecs.fr/httpd.www/echecs/includes/index.inc.php sur la ligne 9
session_start( );

/*echo $_COOKIE['WebChessData'];
exit ('stop');*/

//print_r($_COOKIE); 
/*header('Location: cookies.php');
exit("<br/> Stop");*/
// load 'always needed' settings
require_once './includes/config.inc.php';
require_once './includes/html.inc.php';
//require_once './html.inc.php';
/*if (!empty ($_SESSION['username']))
    $x=24;
    $_SESSION['calcul']=$x;
    header ("Refresh: 1;URL=../reception.php");
    echo $_SESSION['username'];
    exit("<br/> Stop.");*/

// include outside functions
require_once './includes/chessconstants.inc.php';
require_once './includes/chessutils.inc.php';
require_once './includes/gui.inc.php';
require_once './includes/chessdb.inc.php';

/*$_SESSION['username'] = $player;

print_r(array($_SESSION['username']));*/

if (empty($_SESSION['username'])) {
$delai=30; 

    $url='https://jeuxechecs.fr/echecs/login.php';

    header("Refresh: $delai;url=$url");
  	
 //exit("<br/><blockquote><h3>Page en maintenance, vous aller être redirigé sur la page login dans 15 secondes.<br/>Si cela se reproduit, veuillez en avertir le créateur du site.</h3></blockquote>");
 exit("<br/><blockquote><h4>Faisant suite à un problème technique, veuillez effacer les cookies de votre navigateur en correspondance avec le site. Et à fortiori effacer ceux de votre navigateur.</br>
Si vous ne savez pas effacer les cookies de ce jeu, demandez moi comment faire par un message dans une boite à lettre disponible un peu partout sur mon site.</br>
Je vous indiquerai alors précisément comment faire.</br>
Ou changer de navigateur.</h4></blockquote>");
}

/*echo $_COOKIE['WelChessData'];
echo "bonjour";*/
//******************************************************************************
//  load basic information
//******************************************************************************
// check if loading game
if (isset($_POST['game_id']))
{
	$_SESSION['game_id'] = (int) $_POST['game_id'];
}
// make sure we have game id data
if (empty($_SESSION['game_id'])) {
	header('Location: index.php');
	exit;
}
/*if (empty($_SESSION['game_id']) or empty($_SESSION['username']) ) {
header('Location: index.php');
exit;
}*/

if (isset($_SESSION['game_id']) || ! isset($_SESSION['white']))
{
	// get White's data
	$query = "
		SELECT p_id
			, p_username
			, p_email
		FROM ".T_PLAYER."
			, ".T_GAME."
		WHERE ".T_PLAYER.".p_id = ".T_GAME.".g_white_player_id
			AND ".T_GAME.".g_id = '{$_SESSION['game_id']}'
	";
	$_SESSION['white'] = $mysql->fetch_assoc($query, __LINE__, __FILE__);

	// get Black's data
	$query = "
		SELECT p_id
			, p_username
			, p_email
		FROM ".T_PLAYER."
			, ".T_GAME."
		WHERE ".T_PLAYER.".p_id = ".T_GAME.".g_black_player_id
			AND ".T_GAME.".g_id = '{$_SESSION['game_id']}'
	";
	$_SESSION['black'] = $mysql->fetch_assoc($query, __LINE__, __FILE__);

	// get players' color
	if ($_SESSION['white']['p_username'] == $_SESSION['username'])
	{
		$_SESSION['player'] = &$_SESSION['white'];
		$_SESSION['player']['p_color'] = 'white';
		$_SESSION['opponent'] = &$_SESSION['black'];
		$_SESSION['opponent']['p_color'] = 'black';
	}
	else
	{
		$_SESSION['player'] = &$_SESSION['black'];
		$_SESSION['player']['p_color'] = 'black';
		$_SESSION['opponent'] = &$_SESSION['white'];
		$_SESSION['opponent']['p_color'] = 'white';
	}

	// get id960 and position
	$query = "
		SELECT g_id960
		FROM ".T_GAME."
		WHERE g_id = '{$_SESSION['game_id']}'
	";
	$_SESSION['id960'] = $mysql->fetch_value($query, __LINE__, __FILE__);
}
$initpos = id960_to_pos($_SESSION['id960']);

$promoting = false; // init the promotion flag
$undoing   = false; // init the undo flag

// get FEN array (this should probably be in an include somewhere)
$i = 0;
$query = "
	SELECT h_fen
	FROM ".T_HISTORY."
	WHERE h_game_id = '{$_SESSION['game_id']}'
	ORDER BY h_time
";
$FENarray = $mysql->fetch_value_array($query, __LINE__, __FILE__);

$num_moves = count($FENarray) - 1; // remove one for initpos - enlever un pour initpos

loadGame( ); // sets up board using last entry in ".T_HISTORY." table (chessdb.inc.php)
FENtomoves( ); // creates movesArray from FENarray (chessutils.inc.php)
//var_dump($movesArray );
// find out if it's the current player's turn
$FENitems = explode(' ',$FENarray[$num_moves]);
$curTurn  = $colorArray[$FENitems[1]]; // convert w -> white, b -> black

$isPlayersTurn = ($curTurn == $_SESSION['player']['p_color']) ? true : false;

//*/


//******************************************************************************
//  save incoming information - enregistrer les informations entrantes
//******************************************************************************

checkDatabase( ); // check the database data against the current FEN to make sure the game is ended properly (chessdb.inc.php)

processMessages( ); // processes the messages (undo, resign, etc) (chessdb.inc.php)

// are we undoing ?
if ($undoing && 0 < $num_moves)
{
	call("UNDO REQUEST");
	// just remove the last FEN entered into the history table -  supprime simplement le dernier FEN entré dans la table d'historique
	$query = "
		SELECT MAX(h_time)
		FROM ".T_HISTORY."
		WHERE h_game_id = '{$_SESSION['game_id']}'
	";
	$max_time = $mysql->fetch_value($query, __LINE__, __FILE__);

	$query = "
		DELETE FROM ".T_HISTORY."
		WHERE h_game_id = '{$_SESSION['game_id']}'
			AND h_time = '{$max_time}'
		LIMIT 1
	";
	$mysql->query($query, __LINE__, __FILE__);

	if (!DEBUG) header("Location: ./chess.php");
}
// or saving the promotion - ou enregistrer la promotion
elseif ( isset($_POST['promotion']) && '' != $_POST['promotion'] && false != $_POST['promoting'] )
{
	call("SAVING PROMOTION");
	savePromotion( ); // inserts promoted piece and saves to database (chessdb.inc.php)

	if (!DEBUG) header("Location: ./chess.php");
}
// or making a move - ou faire un mouvement.
elseif ( ( isset($_POST['fromRow']) && '' != $_POST['fromRow'] && '' != $_POST['fromCol'] && '' != $_POST['toRow'] && '' != $_POST['toCol'] ) || ( isset($_POST['castleMove']) && 'false' != $_POST['castleMove'] ) )
{
	call("MAKING A MOVE");
	call($_POST);
	call($_POST['fromRow']);

	/* ensure it's the current player moving                                 */
	/* NOTE: if not, this will currently ignore the command...               */
	/*       perhaps the status should be instead?                           */
	/*       (Could be confusing to player if they double-click or something */
	$is_valid = true;
	if ('white' == $curTurn) // white's move
	{
		call("WHITE");
		call($board[$_POST['fromRow']][$_POST['fromCol']]);

		// ensure that piece being moved isn't black (and is a piece)
		if (('black' == $pieceColor[$board[$_POST['fromRow']][$_POST['fromCol']]]) || ('0' == $board[$_POST['fromRow']][$_POST['fromCol']]))
			$is_valid = false; // if test passes, piece was black
	}
	else // black' move
	{
		call("BLACK");
		call($pieceColor[$board[$_POST['fromRow']][$_POST['fromCol']]]);

		// ensure that piece being moved isn't white (and is a piece)
		if (("white" == $pieceColor[$board[$_POST['fromRow']][$_POST['fromCol']]]) || ('0' == $board[$_POST['fromRow']][$_POST['fromCol']]))
			$is_valid = false; // if test passes, piece was white
	}

	if ($is_valid)
	{
		call("IS VALID");
		saveGame( ); // (chessdb.inc.php)

		// reload a fresh page to avoid errors
		// and to display the new database data
		if (!DEBUG) header("Location: ./chess.php");
	}
}
// or we need to select the promoting piece - ou nous devons sélectionner la pièce de promotion.
elseif ('P' == strtoupper($movesArray[$num_moves]['piece']) && ( ! isset($movesArray[$num_moves]['promo']) || null == $movesArray[$num_moves]['promo']))
{
	if($movesArray[$num_moves]['toRow'] == 7 || $movesArray[$num_moves]['toRow'] == 0)
	{
		$promoting = true;
	}
}

// Plus possible de promouvoir un pion.
/*elseif ( !empty($movesArray[$num_moves]) 
      && !empty(($movesArray[$num_moves]['piece']) 
      &&  strtoupper($movesArray[$num_moves]['piece'] == 'P' ) //Sans mouvement de pièces ils est possible de faire la promotion par le ligne suivante.
      ||  empty ($movesArray[$num_moves]['promo']) )) {
          //echo "Bonjour";
 if($movesArray[$num_moves]['toRow'] == 7 || $movesArray[$num_moves]['toRow'] == 0)  {
  $promoting = true;
 }
}*/

/*if (!empty ($promoting))
{
    echo $promoting;//Lorsque $promoting existe, le chiffre 1 est affiché.
}else{
    echo "La variable $promoting est vide ou n'existe pas.";//Ce message apparait lorsqu'il n'y a pas promotion par le pion chez l'adversaire.
}
*/
//******************************************************************************
//  submit chat message
//******************************************************************************
if (isset($_POST['txtChatbox']) && ('' != $_POST['txtChatbox']))
{
	$_POST = sani($_POST);

	$private = (isset($_POST['private']) && 'on' == $_POST['private']) ? 'Yes' : 'No';

	//  select the last post entered and make sure it is not a IE error duplicate message - sélectionnez le dernier message entré et assurez-vous qu'il ne s'agit pas d'un message de duplication d'erreur IE
	// (same message within 1 second) - (même message dans la seconde)
	$query = "
		SELECT COUNT(*)
		FROM ".T_CHAT."
		WHERE c_message = '{$_POST['txtChatbox']}'
			AND c_time BETWEEN
				DATE_SUB(NOW( ), INTERVAL 1 SECOND)
				AND DATE_ADD(NOW( ), INTERVAL 1 SECOND)
	";
	$count = $mysql->fetch_value($query, __LINE__, __FILE__);
	date_default_timezone_set('Europe/Paris');
    $test = new DateTime();
    $d= date_format($test, 'Y-m-d H:i:s');
	if (0 == $count)
	{
	    //$dat= date('d-m-Y-G-i',strtotime("+1 hours"));
	    /*echo $count; $count = 0
	    exit('Stop');*/
	    //echo $_SESSION['player_id']; /*player_id absent.*/
	    //exit('Stop');
		$query = "
			INSERT INTO ".T_CHAT."
				(c_game_id, c_player_id, c_time, c_message, c_private)
			VALUES
				('{$_SESSION['game_id']}', '{$_SESSION['player_id']}', '{$d}', '{$_POST['txtChatbox']}', '{$private}')
		";
		$mysql->query($query, __LINE__, __FILE__);
	}

	// refresh the page to avoid double posts- rafraîchir la page pour éviter les doubles posts
	if (!DEBUG) header('Location: chess.php');
}
//*/


//******************************************************************************
//  send wake up email
//******************************************************************************
$wake_up_sent = false;
if ( isset($_POST['wakeID']) && $_SESSION['game_id'] == $_POST['wakeID'] )
{
    /*echo $_POST['wakeID'];
    echo "<br/>";
    echo $_SESSION['game_id'];
    echo "<br/>";
    echo $_POST['wakeID'];*/
	call ("webchessMail('wakeup',{$_SESSION['opponent']['p_email']},'',{$_SESSION['username']},{$_SESSION['game_id']})");
	$wake_up_sent = webchessMail('wakeup',$_SESSION['opponent']['p_email'],'',$_SESSION['username'],$_SESSION['game_id']);
	/*echo $wake_up_sent;
    exit();
    if ($wake_up_sent) {
        echo "Bonjour";
    }*/
}
//*/


//******************************************************************************
//  load game from database for display
//******************************************************************************

// get FEN array
$query = "
	SELECT h_fen
	FROM ".T_HISTORY."
	WHERE h_game_id = '{$_SESSION['game_id']}'
	ORDER BY h_time
";
$FENarray = $mysql->fetch_value_array($query, __LINE__, __FILE__);

$num_moves = count($FENarray) - 1; // remove one for initpos

loadGame( ); // sets up board using last entry in ".T_HISTORY." table (chessdb.inc.php)

// convert the current FEN array to an array of standard moves
FENtomoves( ); // (chessutils.inc.php)


// find out if it's the current player's turn
$FENitems = explode(' ',$FENarray[$num_moves]);
$curTurn  = $colorArray[$FENitems[1]];

$isPlayersTurn = ($curTurn == $_SESSION['player']['p_color']) ? true : false;

//*/

// set the display to show whos turn, or shared
if ($_SESSION['shared'])
{
	$turn = "Partagé";
}
elseif ($isPlayersTurn)
{
	$turn = "Votre coup";
}
else
{
	$turn = "Coup adverse";
}


$head_extra = '
	<script type="text/javascript">//<![CDATA[
		var watchgame = false;
		function redo( )
		{
			window.location.replace(\'chess.php\');
		}
		';

		// ouput confirmation for wake up email
		if ($wake_up_sent)
		{
			$head_extra .= "alert('Envoi du rappel à répondre à votre coup par e-mail effectué.');\n    ";
		}
		elseif (isset($_POST['wakeID']) && ! $wake_up_sent)
		{
			$head_extra .= "alert('Envoi Wake Up par e-mail échoué !!');\n    ";
		}

		// transfer game data to javacript vars - transférer des données de jeu sur des variables javascript.
		$head_extra .= getJSFEN( );  // writes 'FEN' array, and 'result' (gui.inc.php) - écrit le tableau 'FEN' et 'result' (gui.inc.php)
		$head_extra .= getTurn( );   // writes 'isBoardDisabled', 'isPlayersTurn', and 'perspective' (gui.inc.php) - écrit 'isBoardDisabled', 'isPlayersTurn' et 'perspective' (gui.inc.php)
		$head_extra .= getMoves( );  // writes the 'moves' array (gui.inc.php) - écrit le tableau 'move' (gui.inc.php)
	    $head_extra .= getStatus( ); // writes 'whosMove', 'gameState', and 'statusMsg' (gui.inc.php) - écrit 'whosMove', 'gameState' et 'statusMsg' (gui.inc.php)
//$head_extra .= "console.log('head_moves',moves);";
//$h_status = getStatus();
    //echo $h_status;// => var whosMove = 'A votre adversaire de jouer'; var gameState = ''; var statusMessage = ''; Stop
    //exit ("Stop");
//$head_extra .= $h_status; // writes 'whosMove', 'gameState', and 'statusMsg' (gui.inc.php)

/*$head_extra .= "console.log('head_moves',moves);";
$h_status = getStatus();
$head_extra .= $h_status; // writes 'whosMove', 'gameState', and 'statusMsg' (gui.inc.php)*/

		$head_extra .= "var DEBUG = ".JS_DEBUG.";\n    ";
		$head_extra .= "var numMoves = FEN.length - 1;\n    ";

		// if it's not the player's turn, enable auto-refresh
		$autoRefresh = ( ! $isPlayersTurn && ! isBoardDisabled( ) && ! $_SESSION['shared'] );
		$head_extra .= "var autoreload = ";

		if ( ! $autoRefresh || (0 == $CFG_MINAUTORELOAD) )
		{
			$head_extra .= "0";
		}
		elseif ( $_SESSION['pref_auto_reload'] >= $CFG_MINAUTORELOAD )
		{
			$head_extra .= $_SESSION['pref_auto_reload'];
		}
		else
		{
			$head_extra .= $CFG_MINAUTORELOAD;
		}

		$vs = get_medal($_SESSION['white']['p_username']).$_SESSION['white']['p_username']." - ".get_medal($_SESSION['black']['p_username']).$_SESSION['black']['p_username'];

		$head_extra .= ";
			var gameId = '{$_SESSION['game_id']}';
			var players = '{$vs}';
			var promoting = '{$promoting}';
			var isGameOver = '{$isGameOver}';
			var lastMoveIndicator = '{$_SESSION['pref_show_last_move']}';
			var id960 = '{$_SESSION['id960']}';
			var initpos = '{$initpos}';
			var parties_gagnees = '{$_SESSION['wins']}';
		";

		$head_extra .= "var currentTheme = '";
		$head_extra .= (isset($_SESSION['pref_theme']) ? $_SESSION['pref_theme'] : "Style A") . '\';

			//]]>
		</script>
		<!-- the \'variables\' javascript must come first !! -->
		<script type="text/javascript" src="javascript/variables.js"></script>
		<script type="text/javascript" src="javascript/chessutils.js"></script>
		<script type="text/javascript" src="javascript/commands.js"></script>
		<script type="text/javascript" src="javascript/validation.js"></script>
	';

	if ($isPlayersTurn || $_SESSION['shared'] || $promoting)
	{
		$head_extra .= "\n	<script type=\"text/javascript\" src=\"javascript/isCheckMate.js\"></script>";
	}

	if ( ! isBoardDisabled( ) || $_SESSION['shared'])
	{
		$head_extra .= "\n	<script type=\"text/javascript\" src=\"javascript/squareclicked.js?v=2\"></script>";
	}

	$head_extra .= '<script type="text/javascript" src="javascript/board.js"></script>
		<script type="text/javascript" src="javascript/highlight.js"></script>
	';
	echo get_header(null, $turn, $head_extra)
?>

<div id='centrer_jeu'>
<div id="centrer_menu_partie">
			<a href="index.php"><input type="button" class="button" value="<= Accueil =>"/></a>
				<input type="button" id="btnUndo" class="button" value="Demander à rejouer" />
				<input type="button" id="btnDraw" class="button" value="Demander la nulle" disabled="disabled" />
				<input type="button" id="btnResign" class="button" value="Abandonner" />
				<input type="button" id="btnDraww" class="button" value="Partie pat" disabled="disabled" />
				<a href="#" class="help" onclick="window.open('./help/pat.html','help','resizable,scrollbars,width=550,height=500,top=50,left=50','_blank');return false;"><FONT COLOR="#0000ff">?</a></span>
						
</div>
		<div id="history">
			<?php // case avec dernier coup : ?>
			<span style='display:none;' id="curmove">&nbsp;</span> 
			<h2 id="players"></h2>
			<h2 id="gameid"></h2>
			<div id="gamebody"></div>
		</div>			
		<div id="board">
		
			<div id="checkmsg"></div>
			<div id="statusmsg"></div>
					
		<br>
		
				<div id="gamebuttons">
					<span id="castle">Pour roquer : cliquez sur le roi, et ensuite sur la tour du côté du roque.
					<a href="#" class="help" onclick="window.open('./help/c960castling.html','help','resizable,scrollbars,width=550,height=500,top=50,left=50','_blank');return false;"><FONT COLOR="#0000ff">?</a></span>
				</div>
				
				<form name="gamedata" method="post" action="chess.php">
                <div id="chessboard"></div>
					<?php
					/*if ($promoting){
					    echo "bonjour";*/
					if ($promoting && ( ! $isPlayersTurn || $_SESSION['shared'])) // Write promotion dialog only to the correct player - $promoting absent.
					{
						echo getPromotion( );
					}

					if ($isUndoRequested)
					{
						echo getUndoRequest( );
					}

					if ($isDrawRequested)
					{
						echo getDrawRequest( );
					}
					//}
				?>		
        		<input type="hidden" name="requestUndo" value="no" />
        				<input type="hidden" name="requestDraw" value="no" />
        				<input type="hidden" name="resign" value="no" />
        				<input type="hidden" name="fromRow" value="" />
        				<input type="hidden" name="fromCol" value="" />
        				<input type="hidden" name="toRow" value="" />
        				<input type="hidden" name="toCol" value="<?php if ($promoting) echo $movesArray[$num_moves]['toCol']; ?>" />
        				<input type="hidden" name="castleMove" value="false" />
        				<input type="hidden" name="promoting" value="<?php echo ($promoting ? 'true' : 'false'); ?>" />

                    <div id="confirmationCoup">
                        <div>Etes-vous sûr de vouloir jouer ce coup ?</div>
                        <div>
                            <input id="confirmationCoupBtnNon" type="button" value="Non">
                            <input id="confirmationCoupBtnOui" type="submit" value="Oui">
                        </div>
                    </div>
                </form>
				
			<h3>Pièces capturées:</h3>
			<div id="captheading"></div>
			<div id="captures"></div>
			<br>
			
			<div id="date">
			<?php 
			/*timezone();
			setlocale(LC_TIME,'fr_FR');					 
			echo 'Nous sommes '.strftime("%A %d %B %Y").'. ';
			echo ' Il est: '.strftime("%Hh %M").'<br/>';*/
			?>
			</div>
			<!--<form name="gamedata" method="post" action="chess.php">
				
				<div id="chessboard"></div>-->

					<?php
				/*	if ($promoting && ( ! $isPlayersTurn || $_SESSION['shared'])) // Write promotion dialog only to the correct player
					{
						echo getPromotion( );
					}

					if ($isUndoRequested)
					{
						echo getUndoRequest( );
					}

					if ($isDrawRequested)
					{
						echo getDrawRequest( );
					}*/
				?>
				
			<!--	<input type="hidden" name="requestUndo" value="no" />
				<input type="hidden" name="requestDraw" value="no" />
				<input type="hidden" name="resign" value="no" />
				<input type="hidden" name="fromRow" value="" />
				<input type="hidden" name="fromCol" value="" />
				<input type="hidden" name="toRow" value="" />
				<input type="hidden" name="toCol" value="<?php if ($promoting) echo $movesArray[$num_moves]['toCol']; ?>" />
				<input type="hidden" name="castleMove" value="false" />
				<input type="hidden" name="promoting" value="<?php echo ($promoting ? 'true' : 'false'); ?>" />

			</form>-->
			<div id="gamenav"></div>
			<form name="gamemenu" id="gamemenu" method="post" action="chess.php" style="display:inline;">
				<input type="button" id="btnReload" value="Recharger" disabled="disabled" />
				<input type="button" id="btnReplay" value="Revoir partie" disabled="disabled" />
				<input type="button" id="btnPGN" value="PGN" disabled="disabled" />
			</form>
			<form name="wakeup" id="wakeup" method="post" action="chess.php" style="display:inline;">
				<?php
					// test for opponents email, and if none, disable the wake up button
					$temp = ('' == $_SESSION['opponent']['p_email']) ? ' disabled="disabled"' : ''; // check the var and disable if no email is found
				?>
				<input type="button" id="btnWakeUp" value="Rappel" onclick="wakeUp( );"<?php echo $temp; ?> />
				<input type="hidden" name="wakeID" value="<?php echo $_SESSION['game_id']; ?>" /><a href="#" class="help" onclick="window.open('./help/wakeup.html','help','resizable,scrollbars,width=550,height=500,top=50,left=50','_blank');return false;"><FONT COLOR="#0000ff">?</a>
			</form>
			<h4 style="color: #060200;">1) Pour demander à rejouer un autre coup, il faut cliquer sur le bouton "Demander à rejouer".C'est alors
			que votre adversaire en recevra la demande qu'il sera libre d'accepter ou de refuser.<h4/>
			<!--<h4 style="color: #060200;">2) Si votre adversaire à déjà jouer avant que vous fassiez la demande pour rejouer, il n'est pas trop tard pour lui en faire la demande.
			Pour cela vous devrez lui proposer qu'il vous fasse une demande pour rejouer son coup.Que vous accepterez.
			Puis ensuite vous lui demerez de bien vouloir accepter de rejouer votre coup.</h4>-->
		</div>
		<?php
				// collect the public chat messages
				$query = "
					SELECT distinct c_message
						, c_private
						, p_username
						,DAY(c_time) AS jour, MONTH(c_time) AS mois, Year(c_time) AS annee, HOUR(c_time) AS heure, MINUTE(c_time) AS minute
					FROM ".T_CHAT."
						LEFT JOIN ".T_PLAYER."
							ON ".T_CHAT.".c_player_id = ".T_PLAYER.".p_id
					WHERE c_game_id = '{$_SESSION['game_id']}'
						AND (
							(c_private = 'No')
					";
					
				// include private message data if game is not shared
				if ('1' != $_SESSION['shared'])
				{
					$query .= "
							OR (c_private='Yes'
								AND ".T_CHAT.".c_player_id = '{$_SESSION['player_id']}')
					";
				}

				$query .= "
						)
					ORDER BY c_time DESC
				";
            	
				$result = $mysql->fetch_array($query, __LINE__, __FILE__);
				$i = 0;
				// on n'affiche pas le tableau si on a pas de résultats ..
				$nb_res = count($result); 
				if($nb_res > 0){
				?>
				<div id="chat">
				<h2><center>Chat<center></h2>	
					<div id="date">
					<?php
					/*setlocale(LC_TIME,'fr_FR');	
					//$a=strftime("%A %d %B %Y");
					//echo htmlentities($a);
					//$y='Nous sommes le '.strftime("%A %d %B %Y").'. ';
					echo 'Nous sommes le '.strftime("%A %d %B %Y").'. ';
					//echo $y;
					echo ' Il est: '.strftime("%Hh %M").'<br/>';*/
					timezone();
					?></div>
					
					<div class="info"></div>
					<div id="chatholder">
					<table class="chat" style='table-layout: fixed;'>
						<col />
						<col class="message" />
						<tr>
							<th style='width:90px' >Joueurs</th>
							<th >Messages</th>
						</tr>
				
				<?php }else{ ?>
				<div id="chat">
					<h2>chat</h2>
				<div class="info"></div>
					<div id="chatholder">
					<table class="chat">
						<col />
						<col class="message" />
						<tr>
							<th>Aucun message</th>
						</tr>


				<?php }
				foreach ($result as $chat)
				{
					$alt = ' class="';
					$alt .= (0 == $i % 2) ? ' alt' : '';
					$alt .= ('Yes' == $chat['c_private']) ? ' mine' : '';
					$alt .= ( $_SESSION['username'] != $chat['p_username']  ) ? ' opp' : '';
					$alt .= '"';
					$mois=array("","/ 01 /","/ 02 /","/ 03 /","/ 04 /","/ 05 /","/ 06 /","/ 07 /","/ 08 /","/ 09 /","/ 10 /","/ 11 /","/ 12 /");
					//$mois=array("","janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre");
					$chat['c_message']=nl2br($chat['c_message']); 
					if($chat['minute'] < 10 ){$chat['minute'] = "0".$chat['minute'];}
					echo "
				<tr{$alt}>
					<td class=\"player\">{$chat['p_username']}:<br/>
			        {$chat['jour']} {$mois[$chat['mois']]} {$chat['annee']}<br/> 
					{$chat['heure']}:{$chat['minute']}</td>
					<td style = 'hyphens: auto;word-wrap: break-word;'>  {$chat['c_message']}</td>
				</tr>";
					$i++;
				}
				
/*if (!empty ($_SESSION['username']))
    $x=24;
    $_SESSION['calcul']=$x;
    header ("Refresh: 1;URL=../reception.php");
    echo $_SESSION['username'];
    exit("<br/> Stop.");*/				
				
				?>

			</table>
			</div>
			<br>
			<br>
			<form action="chess.php" method="post" name="chatdata" style="display:inline;">
<textarea style="width:339px;max-width:373px;max-height:90px;" name="txtChatbox" tabindex="2" cols="39" rows="4" onfocus="clearTimeout(intervalId);" onblur="if(''==this.value){intervalId = setTimeout('redo( )', autoreload * 1000);}"
tabindex="2" placeholder="Ecrivez vos commentaires ici..."></textarea> 							
				<br>
				<!--<label for="private"><input type="checkbox" id="private" name="private" tabindex="1" />Privé</label> -->
				 <input type="submit" id="btnSubmit" name="chat" tabindex="3" value="Envoi" />
			</form>
		</div>
		</div>
	</div>
	<div id="footerspacer">&nbsp;</div>
	<?php // NE PAS ENLEVER FENBLOCK : sinon on ne peu plus revoir les coups précédents ?>
	<div id="FENblock"></div>
<?php call($GLOBALS);?>
</body>
</html>
<!-- 
			</table>
			</div>
			<br>
			<br>
			<form action="chess.php" method="post" name="chatdata" style="display:inline;">
				<textarea style="width:339px;max-width:373px;max-height:60px;" name="txtChatbox" tabindex="2" cols="39" rows="4" onfocus="clearTimeout(intervalId);" onblur="if(''==this.value){intervalId = setTimeout('redo( )', autoreload * 1000);}"></textarea> 				
				<br>
				<label for="private"><input type="checkbox" id="private" name="private" tabindex="1" />Privé</label> 
				 <input type="submit" id="btnSubmit" name="chat" tabindex="3" value="Envoi" />
			</form>
		</div>
		</div>
	</div>
	<div id="footerspacer_jeu">&nbsp;</div>
<?php call($GLOBALS);?>
</body>
</html> -->


<?php 
			/*	foreach ($result as $chat)
				{
					$alt = ' class="';
					$alt .= (0 == $i % 2) ? ' alt' : '';
					$alt .= ('Yes' == $chat['c_private']) ? ' mine' : '';
					$alt .= ( $_SESSION['username'] != $chat['p_username']  ) ? ' opp' : '';
					$alt .= '"';
					$mois=array("","/ 01 /","/ 02 /","/ 03 /","/ 04 /","/ 05 /","/ 06 /","/ 07 /","/ 08 /","/ 09 /","/ 10 /","/ 11 /","/ 12 /");
					//$mois=array("","janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre");
					$chat['c_message']=nl2br($chat['c_message']); 
					if($chat['minute'] < 10 ){$chat['minute'] = "0".$chat['minute'];}
					echo "
				<tr{$alt}>
					<td class=\"player\">{$chat['p_username']}:<br/>
			        {$chat['jour']} {$mois[$chat['mois']]} {$chat['annee']}<br/> 
					{$chat['heure']}:{$chat['minute']}</td><br/> 
					";
					$i++;
				}
				
			*/	
?>

Ce warning disparaît lorsque les lignes 236 à 242 sont remplacée par celles allant de 245 à 253.

Comme ci dessous:

/*elseif ('P' == strtoupper($movesArray[$num_moves]['piece']) && ( ! isset($movesArray[$num_moves]['promo']) || null == $movesArray[$num_moves]['promo']))
{
	if($movesArray[$num_moves]['toRow'] == 7 || $movesArray[$num_moves]['toRow'] == 0)
	{
		$promoting = true;
	}
}
*/
// Plus possible de promouvoir un pion.
elseif ( !empty($movesArray[$num_moves]) 
      && !empty(($movesArray[$num_moves]['piece']) 
      &&  strtoupper($movesArray[$num_moves]['piece'] == 'P' ) //Sans mouvement de pièces ils est possible de faire la promotion par le ligne suivante.
      ||  empty ($movesArray[$num_moves]['promo']) )) {
          //echo "Bonjour";
 if($movesArray[$num_moves]['toRow'] == 7 || $movesArray[$num_moves]['toRow'] == 0)  {
  $promoting = true;
 }
}

Mais dans ce cas lorsqu' un pion arrive à la case de promotion (ici g1) pour être remplacer par une autre pièce du jeu, il n'est plus possible de le faire.(Et aucun message d'erreur apparaît.)

Car ce choix représenté ci dessous ne se présente plus lorsque les lignes 236 à 242 sont remplacée par celles allant de 245 à 253 :

Pour obtenir ce choix de promotion il faut que la variable $promoting soit = true; en ligne 251 et grâce a la ligne 505 qui comporte la fonction getPromotion( ) que l'on retrouve à la ligne 194 d'un autre fichier nommé gui.in.php dont voici le scrip ci dessous:

function getPromotion( )
{
	$html = '

	<div class="gameinput">
		Promotion du pion vers:<br />
		<label for="promotionQ"><input type="radio" name="promotion" id="promotionQ" value="Q" checked="checked">Dame</label>
		<label for="promotionR"><input type="radio" name="promotion" id="promotionR" value="R" >Tour</label>
		<label for="promotionN"><input type="radio" name="promotion" id="promotionN" value="N" >Cavalier</label>
		<label for="promotionB"><input type="radio" name="promotion" id="promotionB" value="B" >Fou</label>
		<input type="button" name="btnPromote" value="Promotion" onClick="promotepawn( )" />
	</div>
	';

	return $html;
}

Ensuite je croyais avoir trouvé ce qu'il fallait modifier pour résoudre le problème en remplaçant le ligne 248 ci dessous:

&&  empty($movesArray[$num_moves]['promo']) )) {

par celle ci:

||  empty ($movesArray[$num_moves]['promo']) )) {

Mais dans ce cas ce n'est pas uniquement les pions qui obtiennent la promotion. Un cavalier par exemple, comme ce fut le cas, permet aussi de s'échanger contre une dame par exemple.

Là maintenant je sèche un peu sur ce problème.

Alors si quelqu' un peu me venir en aide, je serai très heureux de découvrir la solution.

Merci.

Windows / Firefox 105.0

3 réponses

Max747 Messages postés 258 Date d'inscription vendredi 11 juillet 2014 Statut Membre Dernière intervention 11 janvier 2024
11 oct. 2022 à 12:33

Rectificatif:

Reprise d'une partie de mon message précédent dont cette ligne est rectifiée:

&&  empty ($movesArray[$num_moves]['promo']) )) {

Ce warning disparaît lorsque les lignes 236 à 242 sont remplacée par celles allant de 245 à 253.

Comme ci dessous:

/*elseif ('P' == strtoupper($movesArray[$num_moves]['piece']) && ( ! isset($movesArray[$num_moves]['promo']) || null == $movesArray[$num_moves]['promo']))
{
	if($movesArray[$num_moves]['toRow'] == 7 || $movesArray[$num_moves]['toRow'] == 0)
	{
		$promoting = true;
	}
}
*/
// Plus possible de promouvoir un pion.
elseif ( !empty($movesArray[$num_moves]) 
      && !empty(($movesArray[$num_moves]['piece']) 
      &&  strtoupper($movesArray[$num_moves]['piece'] == 'P' ) //Sans mouvement de pièces ils est possible de faire la promotion par le ligne suivante.
      &&  empty ($movesArray[$num_moves]['promo']) )) {
          //echo "Bonjour";
 if($movesArray[$num_moves]['toRow'] == 7 || $movesArray[$num_moves]['toRow'] == 0)  {
  $promoting = true;
 }
}

Mais dans ce cas lorsqu' un pion arrive à la case de promotion (ici g1) pour être remplacer par une autre pièce du jeu, il n'est plus possible de le faire.(Et aucun message d'erreur apparaît.)

etc...................................

0
yg_be Messages postés 22731 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 27 avril 2024 1 477
11 oct. 2022 à 13:27

bonjour,

Je pense que cela se produit parce que, arrivé en ligne 236, "$movesArray[$num_moves]" est null.

J'essaierais alors de remplacer la ligne 236 par

elseif isset($movesArray[$num_moves]) 
      && 'P' == strtoupper($movesArray[$num_moves]['piece']) 
      && ( ! isset($movesArray[$num_moves]['promo']) || null == $movesArray[$num_moves]['promo'])
0
Max747 Messages postés 258 Date d'inscription vendredi 11 juillet 2014 Statut Membre Dernière intervention 11 janvier 2024
11 oct. 2022 à 15:33

Bonjour,

effectivement cela fonctionne avec la condition isset qui n'autorise pas le passage aux lignes suivantes quand $movesArray[$num_moves] est nul.Ce qui ne fait plus apparaître le message warning lorsque la partie se présente à son point de départ.

Ainsi après avoir essayé le jeu d'échecs dans toutes ces configurations possibles (promotion du pion par une dame, tour, fou et cavalier) cela fonctionne. Et la promotion ne peut se faire que par le pion cette fois ci !

Merci de m'avoir apporter ton aide qui m'a permis de relancer le jeu. Et par la même occasion d'éclaircir ce mystère.

Problème résolu.

Bien cordialement.

0