Jump to content

ascii chess to opengl board

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
31 replies to this topic

#1
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
ASCII Chess to chess table

hi codecallers,
overview:
the purpose of this project is to convert chess board expressed in ascii into an opengl window with the chess pieces according to the ascii files
how it works:
all it does is reading the board.txt file that contains the ascii text it must be like this format:

bRk|bKn|bBi|bQu|bKi|bBi|bKn|bRk|

---+---+---+---+---+---+---+---  

bP |bP |bP |bP |bP |   |bP |bP |

---+---+---+---+---+---+---+--- 

   |   |   |   |   |   |   |   |

---+---+---+---+---+---+---+--- 

   |   |   |wP |   |bP |   |   |

---+---+---+---+---+---+---+--- 

   |   |   |wQu|   |   |   |   |

---+---+---+---+---+---+---+--- 

   |   |   |   |   |   |   |   |

---+---+---+---+---+---+---+--- 

wP |wP |wP |   |wP |wP |wP |wP |

---+---+---+---+---+---+---+--- 

wRk|wKn|wBi|   |wKi|wBi|wKn|wRk|

-notice the "|" at the end of each line
it reads each line and parses it using the "|" sign and converts the contents (bP ) into an int(-6) that represents the piece
pieces are represented in integers like this:
                // -,+ -->black or white

                //  1,2,3,4,5,6,7  -->piece type, where 1 means empty cell

                //ex: -2 ==>black knight 

                //    6  ==>white king 
the chess pieces are stored into a 2D array, and in the display function each element(chess piece) is drawn with its attributes(the int value) and according to the int value a specific texture is loaded for it

for(int i=0;i<8;i++)

	{

        for(int i2=0;i2<8;i2++)

        { 

            element(x,y,board[i][i2]);

            x+=5;

        }

        y-=5;

        x=-35;

    }


TO DO:
-the black and white cells
-available moves for each piece
-highlighting pieces that are in danger

help?
if anyone can make it better, modify it and post it here. im open for any suggestions or comments

usage:
it works on both windows and linux.
for windows:
you can download the executable and run it perfectly, but place the "board" folder that have the textures in the same place as the exe and the "board.txt" which have the text to be converted
source-code: you can open the project with devcpp using the project file in the attached files, make sure you have the glut package installed
for linux:
-you can compile it by opening the directory that has the project in it "cd asciichess" then make "make" to compile the files. the you can run it from the generated executable called "asciichess"

screenshots:
http://forum.codecal...=1&d=1241501539

Attached Files


yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Awesome! Nice work. Downloading now.
Do you think you could implement URL fetching? This way, we could just enter the URL of our game and see the board graphically.

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Upper left/lower right corners are "white". It looks pretty cool.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
The second row from the left looks like it is taking up two spaces?

#5
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts

Jordan said:

Awesome! Nice work. Downloading now.
Do you think you could implement URL fetching? This way, we could just enter the URL of our game and see the board graphically.
i can google that and see what i can do

WingedPanther said:

Upper left/lower right corners are "white". It looks pretty cool.

Jordan said:

The second row from the left looks like it is taking up two spaces?
spacing and colors altering is screwed up rightnow, i was just so excited with the working version. im working on spacing and black, white cells rightnow
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#6
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Cool! If you need any help fetching the post on this end (server end), let me know.

#7
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
oke doki
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#8
nicckk

nicckk

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 629 posts
Very cool, Amr.

#9
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
changes:
-fixed spacing
-black & white cells
-edit the board.txt file in notepad and press anykey in "ascii board", and it will reload the board from the edited file
http://forum.codecal...=1&d=1241730793

Attached Files


yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#10
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Awesome! Once I get back on my PC I will check it out.

#11
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
looks great!
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#12
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
thnx :D
it wont help me beat you anyways lol
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript