Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

ascii chess to opengl board

ascii

  • Please log in to reply
31 replies to this topic

#1 amrosama

amrosama

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2765 posts

Posted 04 May 2009 - 09:35 PM

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 Thumbnails

  • screen.JPG

Attached Files


  • 1
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_*
  • Guest

Posted 05 May 2009 - 05:51 AM

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.
  • 0

#3 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 05 May 2009 - 06:19 AM

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

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#4 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 05 May 2009 - 06:25 AM

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

#5 amrosama

amrosama

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2765 posts

Posted 05 May 2009 - 08:42 AM

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

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

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
  • 0
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_*
  • Guest

Posted 05 May 2009 - 01:08 PM

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

#7 amrosama

amrosama

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2765 posts

Posted 05 May 2009 - 01:17 PM

oke doki
  • 0
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

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 342 posts

Posted 05 May 2009 - 06:43 PM

Very cool, Amr.
  • 0

#9 amrosama

amrosama

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2765 posts

Posted 07 May 2009 - 01:13 PM

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 Thumbnails

  • screen.JPG

Attached Files


  • 0
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_*
  • Guest

Posted 07 May 2009 - 03:58 PM

Awesome! Once I get back on my PC I will check it out.
  • 0

#11 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 07 May 2009 - 05:33 PM

looks great!
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#12 amrosama

amrosama

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 2765 posts

Posted 07 May 2009 - 05:35 PM

thnx :D
it wont help me beat you anyways lol
  • 0
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





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download