lichess.org
Donate

PGN wiever with C language

@SelfmateMan thank you for the support. Only one thing i could ask you. i made a var with some functions but now i need to create a function to tell to execute these functions (n.0, n.1, n.2, eccetera) How to write this new function???

i have already something like this

[code]

<script>
var currentmove=0;
var moves = [{function one()},{function two()}]

function gotonextmove {if (currentmove < moves.length) <--! DO THE FUNCTION ONE how to write? -->

<script>

[/code]

That's just Object Oriented Programming.

EXAMPLE:

1) You have to create a class:

function book(title, author){
this.title = title;
this.author = author;
this.price = 0;
this.addPrice = addPrice; // Assign that method as property.
}

2) Write the methods (functions) inside the class

// Define a function which will work as a method
function addPrice(amount){
with(this){
price = amount;
}
}

3) Create the object

var myBook = new book("Perl", "Mohtashim");

4) Call the funcions

myBook.addPrice(100);

Link: www.tutorialspoint.com/javascript/javascript_objects.htm
@Andrea_Perrone

to answer your question – if i understood it right:

function one(){... code ...}
function two(){... code ...}
var currentMove = 0;
var moves = [one(), two()];
function goToNextmove(){
if (currentMove < moves.length) {one();}
}

--------------------------------

I have created an example application, called 'Web PGN Viewer' from which you can start. It reflects how it would probably done today. You may not understand it, but it works, so it can be understood.

http://s000.tinyupload.com/?file_id=60241191029065853385
(click the green 'Web_PGN_Viewer.zip' link, download, unzip, start index.html, click in the notation)

The two images are taken from Scid.
Hint:
in Firefox, press ctrl+shift+k.
in the javascript file, add ...
console.log(variable_you_are_interested_in);
... reload, see what happens.

you can also evaluate javascript expressions in the bottom text input of that console.
i just found there is one unnecessary line in the javascript:

observer.model = self;

it is not needed anymore. i forgot to delete it.
i should also note that ...

return [
new Position(
0 , '•', '', [['bk',3,3], ['wk',3,5], ['bp',3,1]]
),
new Position(
1, 'd7-d6', 'and black wins.', [['bk',3,3], ['wk',3,5], ['bp',3,2]]
)
];

... should probably be ...

return make_positions(
'•', 27, 427, 331,
'd7-d6', 'and black wins.', 27, 427, 339
)

... where each number represents a placed piece, which occupys 12 bits, the first six are the position and the last four are the piece type, and where bk = 0 ... wp = 11, and where a8 = 0 ... h1 = 63.

We then work with ...
bqb8 = ((bq << 6) | b8)
bq = (bqb8 >> 6)
b8 = (bqb8 & 63)
b8col = (b8 % 8)
b8row = ((b8 - (b8 % 8)) / 8)

But i was too lazy to implement this.

This topic has been archived and can no longer be replied to.