简体   繁体   English

C ++ 8乘8板

[英]C++ 8 By 8 Board

im trying to implement the n-queen problem board game and im having problems with the board so what am i doing wrong here in this displayboard function? 我正在尝试实现n皇后问题棋盘游戏,并且我在棋盘上遇到问题,所以在此显示板功能中我在做什么错? its suppose to implement an 8 by 8 empty board sorry im just a beginner 它应该实现8 x 8的空白板,对不起,我只是一个初学者

#include <iostream>
#include <limits>

using namespace std;

const int rows = 8;
const int columns =8;

int board[rows][columns] = {0,0};

void displayboard();

int main(){

displayboard();

system("pause");

}
void displayboard ()
{

cout << "  1 2 3 4 5 6 7 8" << endl;
cout << "  ---------------";

for (int bRow = 0; bRow<rows; bRow++)
 {
 for (int bCol = 0; bCol<columns; bCol++)

  if (board[bRow][bCol] == 0)
         cout << " ";
  else 
      cout << " ";
  } 
 cout << endl;

  return;
 }
if (board[bRow][bCol] == 0)
      cout << " ";
else 
      cout << " ";

?? ?? Both do the same thing ! 两者都做同样的事情! Printing a blank space. 打印空白。 Moreover, you haven't populated your array board[8][8] anything other than 0 s. 而且,除了0 s之外,您没有填充阵列board[8][8]

You missed the newlines and possible the white spaces per row. 您错过了换行符,可能错过了每行的空白。 here is a fixed version: (I used a '.' to denote an (empty) field - as it is friendlier to human debugging) 这是一个固定的版本:(我用'。'表示(空)字段-因为它对人工调试更友好)

  1 2 3 4 5 6 7 8
  ---------------
  . . . . . . . . 
  . . . . . . . . 
  . . . . . . . . 
  . . . . . . . . 
  . . . . . . . . 
  . . . . . . . . 
  . . . . . . . . 
  . . . . . . . . 

Code

#include <iostream>
#include <limits>

using namespace std;

const int rows = 8;
const int columns =8;

int board[rows][columns] = {0,0};

void displayboard();

int main()
{
    displayboard();
}

void displayboard ()
{
    cout << "  1 2 3 4 5 6 7 8" << endl;
    cout << "  ---------------";

    for (int bRow = 0; bRow<rows; bRow++)
    {
        cout << "\n  ";
        for (int bCol = 0; bCol<columns; bCol++)
        {
            if (board[bRow][bCol] == 0)
            {
                cout << ".";
            }
            else
            {
                cout << ".";
            }
            cout << " "; // delimiter
        }
    }
    cout << endl;

    return;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM