Author Topic: Chess in Basic  (Read 4711 times)

0 Members and 1 Guest are viewing this topic.

Offline Potato

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 18
  • Rating: +0/-0
    • View Profile
Chess in Basic
« on: September 27, 2011, 05:06:59 pm »
[Edit: Also had another problem.  I wanted to have a banner on the side so that when a piece is selected it showed the name plus a more detailed drawing.  Is there anyway that I can clear just that section of the screen with ease?  I might be able to do clrdraw with what hot_dog suggested since with that I can just remake the board, haven't tried it out, but I want to have a back up plan]

Currently working on Chess in Basic and could use a little bit of help.  So far I've only coded very basic parts of it but I've noticed during testing that it's already a little slow.  In a nutshell what my program does is:

-Display the picture of the chess board (including the pieces already on it.  I chose this method so that I could archive and unarchive pics within the program and also save games)
-Draw the cursor.  
-Get key so that the cursor can move left, right, up and down while also allowing the player to select a piece (by pressing 2nd).
-When 2nd is press the prgm checks the pixels in that square.  It can determine the difference between a black square, white square, and every single piece. (it sees rooks and bishops as the same but this shouldn't be a -problem)
-If a piece is selected it determines what piece it is (it determines if it's a piece at all first) and then what moves are available to it (and if it's a pawn if it's able to "jump" two squares) [at the moment I only have it programmed for pawns).  All available moves are shown with a x through the square and all remaining pixels are darkened (a black square is actually a checkered square).  If 2nd is pressed again on the pawn it reverts the available moves back to their original square type.

But even though I've only programmed white pawns (not even the black pawns yet) it takes about a half second for the cursor to move, and even longer to display the available moves. Before I continue I want to try and speed up this program so that it runs faster and not take 10 seconds per cursor move, (let alone moving to the piece you want)



Other non important stuff:
Each piece is not saved as a pic.  I also plan to have the original pic drawn in using pic on and pic off but only at the end when I'm sure this works.  
Each piece is not a variable.  The program checks the pixels to determine what each square is, not what variable is where.
I actually can't move a piece yet.  I simply haven't programmed it to but I'm fairly confident I could if I decided to put it in.
It will be a person vs person game.  Not a person vs computer game.  I'd rather it have AI but I'm not sure how to make this, if you know how that'd also be helpful. (Keep in mind this is in BASIC).
« Last Edit: September 27, 2011, 06:05:15 pm by Potato »

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Chess in Basic
« Reply #1 on: September 27, 2011, 05:26:17 pm »
I would suggest that you save your chessboard into an 8x8 array if you haven't done so already.  Whatever needs to be done/calculated should be tested in the array.  Any work done with the graphics should simply be drawing them.  (In essence, what you see on the screen is a visual representation of your real chessboard, which is stored in the array)  This will speed up your program.

Here's an example, Matrix [A]:
 0,0,0,0,0,0,0,0
 0,0,0,0,0,0,0,0
 0,0,0,0,0,0,0,0
 0,0,0,0,0,0,0,0
 0,0,0,0,0,0,0,0
 0,0,0,0,0,0,0,0
 1,1,1,1,1,1,1,1
 0,0,0,0,0,0,0,0



You move your cursor to, say, the 7th row and the 1st column of the gameboard, so the calculator checks the 7th row and the 1st column of the array.  Cursor X = 6 and Cursor Y = 1. 

If [A](X,Y)= 1
Goto PN

 "What, ho?  The value is 1!  So the piece is a pawn."  Then the calculator checks to see if the square above is a zero. 

If [A](X, Y-1) = 0
Goto CM

"It's 0!  So the player can move a piece there."

I haven't been programming in Basic for very long, but that's about the big picture.  If you use the array as your chessboard, you should gain some speed.

Offline Potato

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 18
  • Rating: +0/-0
    • View Profile
Re: Chess in Basic
« Reply #2 on: September 27, 2011, 05:32:12 pm »
Oh wow never thought to do it that way.  That's probably a lot faster than what I was doing.  I had it test each a pixel and based off that it would branch off into different things to determine what piece.

Offline boot2490

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 607
  • Rating: +54/-36
    • View Profile
    • Boot2490's Stuff
Re: Chess in Basic
« Reply #3 on: September 27, 2011, 05:53:38 pm »
I suggest using text on the homescreen, like this demo:
[I]=matrix
Code: [Select]
For(Y,1,8)
For(X,1,8)
Output(X,Y,Sub(" PNKBRQ"[I](Y,X)-1,1)
End
End
I have suddenly become really efficient at programming somehow! I don't know. But anyway that should display the entire board in about a second. As long as:
0 = blank space
1 = Pawn
2 = Knight (Night)
3 = King
4 = Bishop
5 = Rook
6 = Queen

However, I don't know about for the black peices...
Although there are asm( things you can put in that make the output text inverted temporarily, so you could figure something out with that...
« Last Edit: September 29, 2011, 01:27:25 pm by boot2490 »
I'm not worried about SOPA creating censorship, that will not stand for long. I'm worried that they'll succeed in stopping piracy!

Spoiler For Signature, updated march 23, 11:28 PM EST:















An useful tool!

PM me if you need some help. I am glad to be of assistance and part of the TI Communnity.

Offline Potato

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 18
  • Rating: +0/-0
    • View Profile
Re: Chess in Basic
« Reply #4 on: September 27, 2011, 06:03:32 pm »
By text do you mean as in clrhome gets rid of it all text? Because I already have graphics drawn out for each piece...


Offline boot2490

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 607
  • Rating: +54/-36
    • View Profile
    • Boot2490's Stuff
Re: Chess in Basic
« Reply #5 on: September 29, 2011, 01:28:28 pm »
yeah, homescreen text. I don't know though. Maybe you should use text sprites on the graph screen.
I'm not worried about SOPA creating censorship, that will not stand for long. I'm worried that they'll succeed in stopping piracy!

Spoiler For Signature, updated march 23, 11:28 PM EST:















An useful tool!

PM me if you need some help. I am glad to be of assistance and part of the TI Communnity.

Offline BalancedFury

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 722
  • Rating: +29/-2
    • View Profile
Re: Chess in Basic
« Reply #6 on: September 29, 2011, 03:07:36 pm »
I absolutely love chess, so I'm waiting for it :D
Antonio Nam = DualBLDR = Tony Arthur... U choose!





JOIN THE PETITION TO ADD THIS EMOTICON!!
[|:{P ------->


Yo dawg I herd u lost the game game so I coded the game game in your calc so you can lose the game game while you code your code about losing the game game.

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Chess in Basic
« Reply #7 on: September 29, 2011, 03:07:55 pm »
You might enjoy doing the sprites as you've been doing.  If you do most of your work on the matrix, then once the game board and everything has been drawn, there's not too much of a speed difference between drawing text and drawing sprites.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Chess in Basic
« Reply #8 on: September 29, 2011, 04:08:45 pm »
Is this being done with TI-BASIC on a TI-83+/84+(SE)?
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline boot2490

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 607
  • Rating: +54/-36
    • View Profile
    • Boot2490's Stuff
Re: Chess in Basic
« Reply #9 on: October 01, 2011, 05:17:39 pm »
Hey, I did some 7x7 chess sprites, and you can use them if you want them.
http://ourl.ca/10180
Should I make them 6x6 so they can be text sprites? Also, they would have some more vertical space.
I'm not worried about SOPA creating censorship, that will not stand for long. I'm worried that they'll succeed in stopping piracy!

Spoiler For Signature, updated march 23, 11:28 PM EST:















An useful tool!

PM me if you need some help. I am glad to be of assistance and part of the TI Communnity.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Chess in Basic
« Reply #10 on: October 01, 2011, 06:11:52 pm »
Text sprites are only five pixels high, not six.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline boot2490

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 607
  • Rating: +54/-36
    • View Profile
    • Boot2490's Stuff
Re: Chess in Basic
« Reply #11 on: October 01, 2011, 09:16:23 pm »
Oh. That would be very hard. VERY hard.
I'm not worried about SOPA creating censorship, that will not stand for long. I'm worried that they'll succeed in stopping piracy!

Spoiler For Signature, updated march 23, 11:28 PM EST:















An useful tool!

PM me if you need some help. I am glad to be of assistance and part of the TI Communnity.

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Chess in Basic
« Reply #12 on: October 02, 2011, 09:18:49 am »
Actually, 5x5 isn't so bad, you'd just have to you pxl-change or pt-change to draw them.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Chess in Basic
« Reply #13 on: October 02, 2011, 11:24:55 am »
Text sprites are only five pixels high, not six.
My Chess text sprites were 6 pixels high, but it only worked for the black pieces.  I used Line()s for the white only but in hindsight it would be easier to just use Line(x,y,x,y,variable) to control if it's black or white. ;)
(I was working on Chess about 2 years ago but gave up because I couldn't figure out how to program the AI).
Here's the program I was displaying with:

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Chess in Basic
« Reply #14 on: October 02, 2011, 12:50:26 pm »
Ya, but you used to characters that aren't traditionally used for doing text sprites. Normal ones are only five since you can't have every combo for the sixth row. But ya, I it is possible as you showed.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)