Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Chess Symbols in C  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I nee help on how to create CHESS Symbols in C programming that looks like this in the picture



Just the Chess symbols, not the whole board.

Any help is appreciated,

Thanks
 
Marshal
Posts: 61741
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Can you display Unicode symbols? Look here.
 
David Simic
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

Can you display Unicode symbols? Look here.



I don't know how to display Unicode symbols, i tried something but it outputs nothing or it does not output the symbol i want.
Can you write a code for one Chess Symbol, just so i can see how it looks like.
I tried googling "how to print Unicode in C" but it mostly shows C++ and the ones i found in C are not working.

BTW, i am using Code Blocks to write C code and compile it.
 
Ranch Hand
Posts: 87
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about something a bit more low tech: here
 
David Simic
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John Matthews wrote:How about something a bit more low tech: here



Thank you for reply,
but is it possible to make something in C that looks like this : https://i.stack.imgur.com/NfBYA.png
 
Campbell Ritchie
Marshal
Posts: 61741
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Shell Meister wrote:. . . is it possible to make something in C that looks like this . . .

Yes, but would you want to? I have found out that you can print Unicode in C++. Haven't found anything for C.
 
David Simic
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Shell Meister wrote:. . . is it possible to make something in C that looks like this . . .

Yes, but would you want to? I have found out that you can print Unicode in C++. Haven't found anything for C.



Yes, i want it to be made in C just the way it looks like in the picture(only chess symbols), but i don't know how.
That's why i'm asking for help
 
Campbell Ritchie
Marshal
Posts: 61741
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know how to draw those little squares, sorry, but I didn't think they looked any good.
 
David Simic
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Don't know how to draw those little squares, sorry, but I didn't think they looked any good.



Just  those little squares on Bishops ?
Can you write King or Knight, or any other symbol(just one ) ?

 
Bartender
Posts: 19984
95
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C and C++ are not that much different, and both are so close to the hardware that it's mostly a matter of brute force.

I believe that there's a compiler switch to force the primitive type "char" to be either traditional (8 bits) or wide (16 bits). You need 16-bit characters to hold the extended Unicode characters. Or you could just plow through with UTF-8, but since all the characters in the chess subset of Unicode are 16 bits anyway, why bother?

Of course, none of this does any good at all unless the output system is set up to display Unicode. So make sure you are outputting to a terminal device (or whatever) that can handle it. And that has been instructed to handle it.
 
David Simic
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:C and C++ are not that much different, and both are so close to the hardware that it's mostly a matter of brute force.

I believe that there's a compiler switch to force the primitive type "char" to be either traditional (8 bits) or wide (16 bits). You need 16-bit characters to hold the extended Unicode characters. Or you could just plow through with UTF-8, but since all the characters in the chess subset of Unicode are 16 bits anyway, why bother?

Of course, none of this does any good at all unless the output system is set up to display Unicode. So make sure you are outputting to a terminal device (or whatever) that can handle it. And that has been instructed to handle it.



I found out that i can't use UNICODE to draw chess table and symbols.
In order to draw this chess table and symbols : https://i.stack.imgur.com/NfBYA.png

Rules are:
1. To define black color field i can use ASCII code 177 and for white field i can use 178
2.To define black figures i can use ASCII 170 and for white 219

So, how can i draw this ??
 
Campbell Ritchie
Marshal
Posts: 61741
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would have to create a 2D array of those characters with the different colours. You could consider having a ready‑made pattern for black queen on white square or similar.
 
Tim Holloway
Bartender
Posts: 19984
95
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I estimate that each square on the sample board is about 10 x 10. There are (if I counted right) 6 distinct shapes, plus blank as possible square values.

You have 2 choices here. One is to use the same definitions for both black and white pieces and adjust the colours as you draw them, the other is simply to hard-code the colours and have double the number of templates (12 instead of 6). You could also draw empty squares from templates, but if not, it's hardly the world's most complex computation.

So for a template, you need a 10x10 element array for each template, and that array would hold the values to be drawn.
 
David Simic
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should i make those patterns using Printf or using for loops ?
 
Tim Holloway
Bartender
Posts: 19984
95
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's your choice. The best way to use printf is if you make each row a string, though.
 
Campbell Ritchie
Marshal
Posts: 61741
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:. . . double the number of templates (12 instead of 6). . . .

More likely twenty‑four. You go from queen to black queen on black square, black queen on white square, white queen on white square and white queen on black square.
 
David Simic
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Tim Holloway wrote:. . . double the number of templates (12 instead of 6). . . .

More likely twenty‑four. You go from queen to black queen on black square, black queen on white square, white queen on white square and white queen on black square.



I have created all patterns,
example of one chess figure looks like this


How can i add this pattern into array ??
 
Campbell Ritchie
Marshal
Posts: 61741
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

David Simic wrote:. . . How can i add this pattern into array ??

I don't think you can; you can have several arrays, but a 2D array usually has to be “rectangular” and can't cope with lines of varying lengths.
I couldn't get 177 and 178 to print with %c; please supply more details.
 
Tim Holloway
Bartender
Posts: 19984
95
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Codes above 128 require extra care. When using them in expressions, the leftmost bit may end up being seen as a sign and extended into an int, meaning a lot more bits than were desired now have 1 values.

I was thinking something more like this:



Much neater and more efficient.

If you prefer to iterate a 2-dimensional unsigned char array and print 1 character at a time, however, use the putc() function, not printf. The printf function is very likely going to call putc for the actual output, but it has a lot more overhead - and in this case, no benefits.
 
Campbell Ritchie
Marshal
Posts: 61741
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried it with const char *sample_row = "\0xb1\0xb2\etc"; but only got a newline as output. I think I am giving up here before I tie anybody else in knots.
 
Rancher
Posts: 539
11
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you really want to implement this have a look at openGL or directX (for windows only) they will let you create a window for rendering on which you could paint the pixels.
But as RC allready pointed out, why would you wan't to? Seems so 80's
 
David Simic
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could it be made using Switch ?

For example to add letter K in the array and then use
Switch

case 'K'

and then write pattern

??
 
Tim Holloway
Bartender
Posts: 19984
95
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you could do something like this:



There are many ways to code this even in ASCIIZ-art mode, and that's before you get into a true graphics environment like OpenGL.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!