Author Topic: [C++] Graphic preview  (Read 2389 times)

0 Members and 1 Guest are viewing this topic.

Offline Code.Illusionist

  • Royal Highness
  • ****
  • Posts: 687
  • Cookies: 39
  • Compile or die trying
    • View Profile
[C++] Graphic preview
« on: December 04, 2013, 03:52:38 pm »
I have task to calculate how many combinations there are to set on chess board two rooks in way they don't att each other. So I solved that part with this loop:
Code: [Select]
for(int i= 0; i <7; i++)
                 for(int j = 0; j < 8; j++) {
                         if(i==0) rezultat += 49;
                         if(i==1) rezultat += 42;
                         if(i==2) rezultat += 35;
                         if(i==3) rezultat += 28;
                         if(i==4) rezultat += 21;
                         if(i==5) rezultat += 14;
                         if(i==6) rezultat += 7;
                        }
                     parametar = rezultat ;
But, not I'd like to make graphic preview of all combinations (1568 in total) . For example I'd like first image to be like this:

Second image would be:

As you see the images will move that rook to the right until he reach last field, then he will move to next line and to all that again and again till he reach last bottom field in the right. That's totaly 49 pictures. After that, first rook will move one step to right and then second rook will be set in first column and repeat all this moving to right avoiding second column (because there is another rook) . After first rook reach end of row, he will move to second row and everything will be totaly same, same moving etc. How can I make that graphicly with console application? I was thinking a lot about it but only way I could think of is tooooo many if statements. Is there any shorter way?
« Last Edit: December 09, 2013, 06:27:31 pm by Kulverstukas »
Vae Victis - suffering to the conquered

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: [C++] Graphic preview
« Reply #1 on: December 04, 2013, 04:26:55 pm »
Are you sure there are only 1568 combination to place two rocks(?). Are the rocks "different/unique", as in: Is rock A on position 1 and rock B on position 2 the same as rock A on position 2 and rock B on position 1? If so you have to do something like this:

[gist]anonymous/7789257[/gist]


Also for the "graphical" preview, I would go ASCII art like this:

+----+----+----+----+----+----+----+----+
|    |  A |    |    |    |    |    |    |
+----+----+----+----+----+----+----+----+
|    |    |    |    |    |    |    |    |
+----+----+----+----+----+----+----+----+
|    |    |    |    |    |    |    |    |
+----+----+----+----+----+----+----+----+
|    |    |    |    |    |    |    |    |
+----+----+----+----+----+----+----+----+
|    |    |    |    |    |    |    |    |
+----+----+----+----+----+----+----+----+
|    |    |    |  B |    |    |    |    |
+----+----+----+----+----+----+----+----+
|    |    |    |    |    |    |    |    |
+----+----+----+----+----+----+----+----+
|    |    |    |    |    |    |    |    |
+----+----+----+----+----+----+----+----+
« Last Edit: December 04, 2013, 04:27:43 pm by ande »
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline Code.Illusionist

  • Royal Highness
  • ****
  • Posts: 687
  • Cookies: 39
  • Compile or die trying
    • View Profile
Re: [C++] Graphic preview
« Reply #2 on: December 04, 2013, 05:01:52 pm »
They are same rooks. Not black and white, but both white or just black. And what you made there is one amazing graphical drawing, just problem is I don't know how to fill it with loops. It would be crazy to draw each chess board for so much combinations. :D
Vae Victis - suffering to the conquered

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: [C++] Graphic preview
« Reply #3 on: December 04, 2013, 05:12:13 pm »
They are same rooks. Not black and white, but both white or just black. And what you made there is one amazing graphical drawing, just problem is I don't know how to fill it with loops. It would be crazy to draw each chess board for so much combinations. :D

You could do something like this:
[gist]anonymous/7790285[/gist]


EDIT: Eheh, clearly I have been doing too much PHP lately :P Change "function" to void or something.
« Last Edit: December 04, 2013, 05:14:17 pm by ande »
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline Stackprotector

  • Administrator
  • Titan
  • *
  • Posts: 2515
  • Cookies: 205
    • View Profile
Re: [C++] Graphic preview
« Reply #4 on: December 04, 2013, 05:15:52 pm »
You could do something like this:
[gist]anonymous/7790285[/gist]


EDIT: Eheh, clearly I have been doing too much PHP lately :P Change "function" to void or something.
« Last Edit: December 09, 2013, 06:29:01 pm by Kulverstukas »
~Factionwars

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: [C++] Graphic preview
« Reply #5 on: December 04, 2013, 05:16:41 pm »
This one is tested and works:

[gist]anonymous/7790347[/gist]
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline Code.Illusionist

  • Royal Highness
  • ****
  • Posts: 687
  • Cookies: 39
  • Compile or die trying
    • View Profile
Re: [C++] Graphic preview
« Reply #6 on: December 04, 2013, 10:12:42 pm »
I was trying to understand what you did here but no chance. I see you have function parameters, but I guess they are changeable , and in this example I don't see how they are changed? =/
Vae Victis - suffering to the conquered

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: [C++] Graphic preview
« Reply #7 on: December 05, 2013, 12:32:03 am »
Hope this makes more sense:

[gist]anonymous/7797593[/gist]

PS: I got 2016 possible combinations. Not 1000% sure I am correct, but going through the first three Y lines X by X it looks like its calculating correctly.
« Last Edit: December 05, 2013, 12:36:08 am by ande »
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline Code.Illusionist

  • Royal Highness
  • ****
  • Posts: 687
  • Cookies: 39
  • Compile or die trying
    • View Profile
Re: [C++] Graphic preview
« Reply #8 on: December 05, 2013, 01:26:44 am »
Thanks for this. The reason why you get that number is because you set first for loop to repeat 8 times. That just shouldn't happen. Why? Well, when you have rook in top left position, and he slowly progress down, he will make other rook to move down to and don't allow him to go above. Since they are both same color and it has no sence one of them come again on the top (combinations will repeat). So, as he move down, he will reach row 7 and when he is done with moving there, it has no sense again to go to last row. because again, the other rook just did that combinations, it will be repeat again. First loop should happen 7 times, second one 8 times, third one 8 times and last one is dynamic. it's dynamic because when first loop increase, the field for second rook will decrease slowly. From 7 possible rows to move, to 6, then to 5 etc.
Vae Victis - suffering to the conquered

Offline Code.Illusionist

  • Royal Highness
  • ****
  • Posts: 687
  • Cookies: 39
  • Compile or die trying
    • View Profile
Re: [C++] Graphic preview
« Reply #9 on: December 09, 2013, 04:51:34 pm »
Update: I just realised how foolish I am. I told you that rooks are from the same color while they are not. OMG. Now this loops won't do the job that should be done xXD
Vae Victis - suffering to the conquered

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: [C++] Graphic preview
« Reply #10 on: December 09, 2013, 07:20:27 pm »
Update: I just realised how foolish I am. I told you that rooks are from the same color while they are not. OMG. Now this loops won't do the job that should be done xXD

The loops I supplied will do that as well. The only think you will need to do is remove some of the if statement stuff.


EDIT: Just do something like: if((rockaPosX != rockbPosX || rockaPosY != rockbPosY))
« Last Edit: December 09, 2013, 07:20:57 pm by ande »
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true