473,473 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

chessboard and list of moves

I have an html page which, thanks to some javascript, allows to move pieces
on
a chessboard.
I can't find how to reflect the moves in a list displayed by the same page.
To understand what I'm trying to do you can have a look at:
http://mdevat.phpnet.org/echecs/firstmoves.php
(don't be misleaded by the .php nor by the code, I'm just revamping
everything
to drop the php content and have an html + javascipt page)
I looked for example of simple chessboards with list of moves and could not
find anything .
Jul 20 '05 #1
1 2657
"Michel" <Mi**************@wanadoo.fr> writes:
I have an html page which, thanks to some javascript, allows to move pieces
on a chessboard.
No verification that the move is legal, or even that it's the right
color, though.
I can't find how to reflect the moves in a list displayed by the same page.
What have you tried?
To understand what I'm trying to do you can have a look at:
http://mdevat.phpnet.org/echecs/firstmoves.php
(don't be misleaded by the .php nor by the code, I'm just revamping
everything to drop the php content and have an html + javascipt page)


Yes, quite simple design.

Ok, you move the piece in the second part of the "mdown" function (after
the "else"). That would be the obvious place to update the list too.

When you move the piece, you have the row and column of the target as
numbers, and as strings ("rowdest", "coldest", "roworig", and "colorig").
The column names are not assigned correctly. After each case in the switch,
you should add "break;", otherwise it continues with the next case.

You have tried combining them too, but failed (there shouldn't be quotes
around the variable names).

The text fields in the list are named "movewhite[0]", "moveblack[0]",
"movewhite[1]", etc.

They will probably be missing in some browsers, since the are placed
*after* "</body></html>". Don't do that. Actually, it seems you have
put an entire page, from <head> to </html>, inside another page. Fix
that, and make the HTML validate!

Anyway, to write to "movewhite[0]", you would write
document.forms[0].elements["movewhite[0]"].value = ...;

To write the moves one after another, you would need to track which
color it is and which move is next. You can use one or two variables
for that. Two is easier to read.

Add this to the beginning of the script tag;

var colors = ["white","black"];
var color = 0;
var movenumber = 0;

Then at the end of the else branch in mdown, replace the last two
lines with:

if (movenumber < 13) { // you only have 13 input fields, so stop writing
document.forms[0].elements["move"+colors[color]+"["+movenumber+"]"].
value = colorig + roworig + coldest + rowdest;
color++; // increment color, 0=white,1=black,2=goto 0, but increment move
if (color == 2) {
color = 0;
movenumber++;
}
}

The page needs serious work (the HTML is disasterous), but it seems to work
with the above changes (remember the "break" statements).

Good luck.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tony Johansson | last post by:
Hello! Assume you want to store field object that a chess board consist of. A chess board consist of 64 fields where each field is either white or black. Now to my question how should I...
4
by: Jeremy Ames | last post by:
I am trying to add info into a list box but I am having problems. I am trying to load the information into a tabular format within the list box, but when I try to space everything out, I get...
7
by: fidtz | last post by:
The code below works fine, but it is less than nice to look at and somewhat long winded. Is there a better way to do the docstring task? This is the first working version, and can proabably be...
6
by: tommy34 | last post by:
I'm new to java and any help will be appreciated. Problem is i dont know even where to start. I need to write a program that reads a chessboard configuration and identifies whether a king is...
4
by: punkybrewster | last post by:
I have the idea to create the program but I need help in finishing it. My task is to write a program that prints out a chessboard using only asterisks. I have to use multiple nested loops with...
1
by: D Lutheran | last post by:
I need to write some code in some navigation buttons to have the button move up and down list box items. I think I need to start with having the button change an index the buttons are...
16
by: agent-s | last post by:
Basically I'm programming a board game and I have to use a list of lists to represent the board (a list of 8 lists with 8 elements each). I have to search the adjacent cells for existing pieces and...
1
by: satish100 | last post by:
how can i write a program for making the plain chessboard in PHP
8
by: vmanrao | last post by:
Hey guys I'm a beginner with C++ and am doing a practice problem for my class and am having trouble figuring this problem out. A man wants 1 grain for the 1st square on a chessboard. 2 grains on...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.