战舰AI实施

时间:2015-04-11 07:33:54

标签: c++ algorithm search artificial-intelligence probability

this文章的演练部分中的数字很好地详细说明了算法。

我开发了以下短程序:

#include <iostream>
using namespace std;

int main() {
    int arr['K' - 'A'][10 - 0] = {0};
    int largestShip;

    //grid
    cout << "   ";
    for(int i = 0; i < 10; i++) {
        cout << (i + 1) % 10;
    }
    cout << endl << "  ____________" << endl;;

    for(char c = 'A'; c < 'K'; c++) {
        cout << c << " |";
        for(int i = 0; i < 10; i++) {
            cout << arr[c - 'A'][i];
        }
        cout << "|" << endl;
    }
    cout << endl;
    //endgrid

    //heatmap
    largestShip = 5;
    for(char c = 'A'; c < 'K'; c++) {
        for(int i = 0; (i + largestShip - 1) < 10; i++) {
            for(int j = 0; j < largestShip; j++) {
                arr[c - 'A'][j + i]++;
            }
        }
    }
    for(char c = 'A'; (c + largestShip - 1) < 'K'; c++) {
        for(int i = 0; i  < 10; i++) {
            for(int j = 0; j < largestShip; j++) {
                arr[c - 'A' + j][i]++;
            }
        }
    }
    //endheatmap

    //showheatmap
    cout << "   ";
    for(int i = 0; i < 10; i++) {
        cout << (i + 1) % 10;
    }
    cout << endl << "  ____________" << endl;;

    for(char c = 'A'; c < 'K'; c++) {
        cout << c << " |";
        for(int i = 0; i < 10; i++) {
            cout << arr[c - 'A'][i] % 10;
        }
        cout << "|" << endl;
    }
    cout << endl;
    //endshowheatmap

    return 0;
}

它设置正方形的初始概率,其优先级由值数组中相应整数值的大小设置。

然而,我对概率论并不十分精通,并且不确定如何处理和理解操纵平方概率(以及通过关联,它们的值)的必要方法,以便准确地分配概率在该广场拍摄了一些拍摄后的任何广场。

关于镜头对网格中方块概率值的影响的解释将是有帮助的。

0 个答案:

没有答案