所以我想打印一个tic-tac-toe board但是如果没有得到疯狂的结果就无法解决这个问题
#include <iostream>
int main()
{
const int ROWS = 3;
const int COLUMNS = 3;
char board[ROWS][COLUMNS] =
{ {'X', 'O', 'X'},
{' ', 'O', 'O'},
{'X', 'X', 'O'} };
for (int i = 0; i < COLUMNS; i++)
{
for (int j = 0; j < ROWS; j++)
{
std::cout << board[0][j];
}
std::cout << "\n";
}
}
答案 0 :(得分:1)
打印输出从不迭代电路板的行。此外,您已将行和列混合在一起,让外循环(第一个)在ROWS上迭代,在内部在COLUMNS上迭代。
更改
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4g"
}
defaultConfig {
applicationId "maa.myapp"
minSdkVersion 15
targetSdkVersion 26
versionCode 43
versionName "4.1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}
android {
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
}
dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//notifications
compile 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.github.chrisbanes:PhotoView:2.1.3'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.support:multidex:1.0.2'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.github.bumptech.glide:glide:4.5.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.slider:library:1.1.5@aar'
compile 'com.google.android.gms:play-services-ads:11.8.0'
compile 'com.google.firebase:firebase-core:11.8.0'
compile 'com.google.firebase:firebase-messaging:11.8.0'
compile 'com.firebase:firebase-jobdispatcher:0.6.0'
compile 'com.vodyasov:amr:0.5'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
compile 'com.google.guava:guava:23.6-android'
testCompile 'junit:junit:4.12'
compile 'com.squareup:otto:1.3.8'
}
apply plugin: 'com.google.gms.google-services'
到
for (int i = 0; i < COLUMNS; i++) {
for (int j = 0; j < ROWS; j++) {
std::cout << board[0][j];
}
std::cout << "\n";
}
答案 1 :(得分:0)
您只是反复打印第一行,即std::cout << board[0][j];
应该是std::cout << board[i][j];
。
答案 2 :(得分:0)
您似乎使用了错误的第一个索引,0
而不是i
!所以替换你的行
std::cout << board[0][j];
与
std::cout << board[i][j];
它工作正常!
P.S。在2003年,我写了我的毕业论文与“博弈论”,其中一个最重要的例子是tic-tac-toe游戏,我在Visual Basic 97中实现了动画,音频和非失败策略电脑播放器。你可能还会看到我的家庭视频,关于与幽灵玩家的tic-tac-toe: https://youtu.be/1kL-1lqAt6Y