Problema de juicio de Gobang en prueba de máquina

Dos ideas principales:

1. Escanee el tablero directamente y recorra uno por uno en cuatro direcciones, lo que no solo es problemático sino también tonto;

2. Cada vez que se deja caer a un niño, las cuatro direcciones del niño se juzgan directamente, y las direcciones izquierda y derecha se pueden resumir en una dirección;

 

#include <iostream> 
#include <vector> 
#include < string >
 usando el  espacio de nombres std; 

const  int maxn = 13 ;
int ma [maxn] [maxn]; 

vacío printma () {
     for ( int i = 0 ; i <maxn; i ++ ) {
         for ( int j = 0 ; j <maxn; j ++ ) {
             if (ma [i] [j] == 1 ) { 
                cout << " o " ; 
            }
            más  si (ma [i] [j] == - 1 ) { 
                cout << " x " ; 
            } 
            else { 
                cout << " # " ; 
            } 
            cout << "  " ; 
        } 
        cout << endl; 
    } 
} 

int henc ( int x, int y) {
     int cnt = 0 ;
    para ( inti = x; i <maxn && ma [x] [y] == ma [i] [y]; i ++ ) { 
        cnt ++ ; 
    } 
    para ( int i = x - 1 ; i> = 0 && ma [x] [y] == ma [i] [y]; i-- ) 
        cnt ++ ;
    volver cnt; 
} 

int shuc ( int x, int y) {
     int cnt = 0 ;
    para ( int i = y; i <maxn && ma [x] [y] == ma [x] [i]; i ++ ) { 
        cnt ++ ; 
    } 
    para ( inti = y - 1 ; i> = 0 && ma [x] [y] == ma [x] [i]; i-- ) 
        cnt ++ ;
    volver cnt; 
} 

int xzc ( int x, int y) {
     int cnt = 0 ;
    para ( int i = x, j = y; i <maxn && y <maxn && ma [x] [y] == ma [i] [j]; i ++, j ++ ) { 
        cnt ++ ; 
    } 
    para ( int i = x- 1 , j = y- 1 ; i> = 0 && y> = 0 && ma [x] [y] == ma [i] [j]; i--, j--) { 
        cnt ++ ; 
    } 
    return cnt; 
} 

int xyc ( int x, int y) {
     int cnt = 0 ;
    para ( int i = x, j = y; i> = 0 && y <maxn && ma [x] [y] == ma [i] [j]; i--, j ++ ) { 
        cnt ++ ; 
    } 
    para ( int i = x, j = y; i <maxn && y> = 0 && ma [x] [y] == ma [i] [j]; i ++, j-- ) { 
        cnt ++ ; 
    } 
    return cnt; 
}

carga bool ( int x, int y) {
     if (henc (x, y) == 5 || shuc (x, y) == 5 || xzc (x, y) == 5 || xyc (x, y ) == 5 )
         devuelve  verdadero ;
    de lo contrario 
        devuelve  falso ; 
} 

int main () {
     int x, y;
    int f = 1 ;
    mientras que ( 1 ) { 
        cin >> x >> y; 
        ma [x] [y] = f; 
        printma (); 
        Si(carga (x, y)) {
             if (f == 1 ) { 
                cout << " 黑 o 胜利" << endl; 
            } 
            else { 
                cout << " 白 x 胜利" << endl; 
            } 
            Romper ; 
        } 
        f = - f; 
    } 
    retorno  1 ; 
}

 

Supongo que te gusta

Origin www.cnblogs.com/songlinxuan/p/12688294.html
Recomendado
Clasificación