Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
24 kB
4
Indexable
Never
//I don't know why
#pragma once

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <set>
#include <vector>
using namespace std;

//I don't know why
// #define max(a,b) ((a>b)?a:b)
// #define min(a,b) ((a<b)?a:b)



//----------state.hpp----------//

typedef bitset<15> Row;
typedef array<Row,15> Min_min_B;
typedef array<Min_min_B,3> The_Board;
const int SIZE = 15;
int player;
array<std::array<int, SIZE>, SIZE> board;

//I don't know why

void start();

enum SPOT_STATE {
    EMPTY = 0,
    BLACK = 1,
    WHITE = 2
};

enum Game{
    Still,Dont_kown,
    Lose,Tie
};

struct Point {
  int x, y;
	Point() : Point(0, 0) {}
	Point(float x, float y) : x(x), y(y) {}
	bool operator==(const Point& rhs) const {
		return x == rhs.x && y == rhs.y;
	}
	bool operator!=(const Point& rhs) const {
		return !operator==(rhs);
	}
	Point operator+(const Point& rhs) const {
		return Point(x + rhs.x, y + rhs.y);
	}
	Point operator-(const Point& rhs) const {
		return Point(x - rhs.x, y - rhs.y);
	}
};
std::vector<Point> to_move;


const int Beside[8][2]{
    {1,1},{-1,-1},
    {1,-1},{-1,1},
    {1,0},{-1,0},
    {0,1},{0,-1}
};

class Thing{
    public:
        Thing(){};
        Thing(The_Board map,int people);
        Thing* The_nextone(Point mov);
        vector<Point> behavior;
        Game look_id();
        int values();
    private:
        int player;
        The_Board map;
        Game id=Dont_kown;
        vector<Point> The_behavior();
};

//----------minimax.hpp----------//

//I don't know why here
// template<class Demon>
// inline size_t argmax(Demon first, Demon last){
//   return distance(first, std::max_element(first, last));
// }

class Minimax{
    public:
        static int values(Thing * status,int th);
        static Point moving(Thing *status,int th);
};

//----------state.cpp----------//

void start(){
    for(int i=0;i<15;i++){
        for(int j=0;j<15;j++){
            to_move.push_back(Point(i,j));
        }
    }
}

int continuous_5(Min_min_B map){
    for(int i=0;i<11;i++){
        if((map[i] & map[i+1] & map[i+2] & map[i+3] & map[i+4]).any())
            return 1;
        if((map[i] & map[i+1]>>1 & map[i+2]>>2 & map[i+3]>>3 & map[i+4]>>4).any())
            return 1;
        if((map[i] & map[i+1]<<1 & map[i+2]<<2 & map[i+3]<<3 & map[i+4]<<4).any())
            return 1;
        
        for(int j=0;j<15;j++){
            if(((map[j]>>i)&=0b11111) ==0b11111)
                return 1;
        }
    }
    return 0;
}

int continuous_4(Min_min_B map,Min_min_B nobody){
    for(int i=0;i<10;i++){
        if((nobody[i] & map[i+1] & map[i+2] & map[i+3] & map[i+4] & nobody[i+5]).any())
            return 1;
        if((nobody[i] & map[i+1]>>1 & map[i+2]>>2 & map[i+3]>>3 & map[i+4]>>4 & nobody[i+5]>>5).any())
            return 1;
        if((nobody[i] & map[i+1]<<1 & map[i+2]<<2 & map[i+3]<<3 & map[i+4]<<4 & nobody[i+5]<<5).any())
            return 1;
        
        for(int j=0;j<15;j++){
            if(((map[j]>>i)&=0b011110) ==0b011110 && ((nobody[j]>>i)&=0b100001) ==0b100001)
                return 1;
        }
    }
    return 0;
}

int die_4(Min_min_B map,Min_min_B nobody,Min_min_B other){
    int values=0;
    for(int i=0;i<11;i++){
        if((map[i] & nobody[i+1] & map[i+2] & map[i+3] & map[i+4]).any())
            values++;
        if((map[i] & nobody[i+1]>>1 & map[i+2]>>2 & map[i+3]>>3 & map[i+4]>>4).any())
            values++;
        if((map[i] & nobody[i+1]<<1 & map[i+2]<<2 & map[i+3]<<3 & map[i+4]<<4).any())
            values++;

        if((map[i] & map[i+1] & map[i+2] & nobody[i+3] & map[i+4]).any())
            values++;
        if((map[i] & map[i+1]>>1 & map[i+2]>>2 & nobody[i+3]>>3 & map[i+4]>>4).any())
            values++;
        if((map[i] & map[i+1]<<1 & map[i+2]<<2 & nobody[i+3]<<3 & map[i+4]<<4).any())
            values++;

        if((nobody[i] & map[i+1] & map[i+2] & map[i+3] & map[i+4] & other[i+5]).any())
            values++;
        if((nobody[i] & map[i+1]>>1 & map[i+2]>>2 & map[i+3]>>3 & map[i+4]>>4 & other[i+5]>>5).any())
            values++;
        if((nobody[i] & map[i+1]<<1 & map[i+2]<<2 & map[i+3]<<3 & map[i+4]<<4 & other[i+5]<<5).any())
            values++;

        if((other[i] & map[i+1] & map[i+2] & map[i+3] & map[i+4] & nobody[i+5]).any())
            values++;
        if((other[i] & map[i+1]>>1 & map[i+2]>>2 & map[i+3]>>3 & map[i+4]>>4 & nobody[i+5]>>5).any())
            values++;
        if((other[i] & map[i+1]<<1 & map[i+2]<<2 & map[i+3]<<3 & map[i+4]<<4 & nobody[i+5]<<5).any())
            values++;

        if((map[i] & map[i+1] & nobody[i+2] & map[i+3] & map[i+4]).any())
            values++;
        if((map[i] & map[i+1]>>1 & nobody[i+2]>>2 & map[i+3]>>3 & map[i+4]>>4).any())
            values++;
        if((map[i] & map[i+1]<<1 & nobody[i+2]<<2 & map[i+3]<<3 & map[i+4]<<4).any())
            values++;
        
        for(int j=0;j<15;j++){
            if(((map[j]>>i)&=0b10111) ==0b10111 && ((nobody[j]>>i)&=0b01000) ==0b01000)
                values++;
            if(((map[j]>>i)&=0b11101) ==0b11101 && ((nobody[j]>>i)&=0b00010) ==0b00010)
                values++;
            if(((map[j]>>i)&=0b011110) ==0b011110 && ((nobody[j]>>i)&=0b100000) ==0b100000 && ((other[j]>>i)&=0b000001) ==0b000001)
                values++;
            if(((map[j]>>i)&=0b011110) ==0b011110 && ((nobody[j]>>i)&=0b000001) ==0b000001 && ((other[j]>>i)&=0b100000) ==0b100000)
                values++;
            if(((map[j]>>i)&=0b10111) ==0b10111 && ((nobody[j]>>i)&=0b01000) ==0b01000)
                values++;
            if(((map[j]>>i)&=0b11011) ==0b11011 && ((nobody[j]>>i)&=0b00100) ==0b00100)
                values++;
        }
    }
    return values;
}

int live_3(Min_min_B map,Min_min_B nobody){
    int values=0;
    for(int i=0;i<11;i++){
        if((nobody[i] & map[i+1] & map[i+2] & map[i+3] & nobody[i+4]).any())
            values++;
        if((nobody[i] & map[i+1]>>1 & map[i+2]>>2 & map[i+3]>>3 & nobody[i+4]>>4).any())
            values++;
        if((nobody[i] & map[i+1]<<1 & map[i+2]<<2 & map[i+3]<<3 & nobody[i+4]<<4).any())
            values++;

        if((nobody[i] & map[i+1] & nobody[i+2] & map[i+3] & map[i+4] & nobody[i+5]).any())
            values++;
        if((nobody[i] & map[i+1]>>1 & nobody[i+2]>>2 & map[i+3]>>3 & map[i+4]>>4 & nobody[i+5]>>5).any())
            values++;
        if((nobody[i] & map[i+1]<<1 & nobody[i+2]<<2 & map[i+3]<<3 & map[i+4]<<4 & nobody[i+5]<<5).any())
            values++;

        if((nobody[i] & map[i+1] & map[i+2] & nobody[i+3] & map[i+4] & nobody[i+5]).any())
            values++;
        if((nobody[i] & map[i+1]>>1 & map[i+2]>>2 & nobody[i+3]>>3 & map[i+4]>>4 & nobody[i+5]>>5).any())
            values++;
        if((nobody[i] & map[i+1]<<1 & map[i+2]<<2 & nobody[i+3]<<3 & map[i+4]<<4 & nobody[i+5]<<5).any())
            values++;

        for(int j=0;j<15;j++){
            if(((map[j]>>i)&=0b01110) ==0b01110 && ((nobody[j]>>i)&=0b10001) ==0b10001)
                values++;
            if(((map[j]>>i)&=0b010110) ==0b010110 && ((nobody[j]>>i)&=0b101001) ==0b101001)
                values++;
            if(((map[j]>>i)&=0b011010) ==0b011010 && ((nobody[j]>>i)&=0b100101) ==0b100101)
                values++;
        }
    }
    return values;
}

int sleep_3(Min_min_B map,Min_min_B nobody,Min_min_B other){
    int values=0;
    for(int i=0;i<11;i++){
        //..OOOX
        if((nobody[i] & nobody[i+1] & map[i+2] & map[i+3] & map[i+4] & other[i+5]).any())
            values++;
        if((nobody[i] & nobody[i+1]>>1 & map[i+2]>>2 & map[i+3]>>3 & map[i+4]>>4 & other[i+5]>>5).any())
            values++;
        if((nobody[i] & nobody[i+1]<<1 & map[i+2]<<2 & map[i+3]<<3 & map[i+4]<<4 & other[i+5]<<5).any())
            values++;
        //XOO..
        if((other[i] & map[i+1] & map[i+2] & map[i+3] & nobody[i+4] & nobody[i+5]).any())
            values++;
        if((other[i] & map[i+1]>>1 & map[i+2]>>2 & map[i+3]>>3 & nobody[i+4]>>4 & nobody[i+5]>>5).any())
            values++;
        if((other[i] & map[i+1]<<1 & map[i+2]<<2 & map[i+3]<<3 & nobody[i+4]<<4 & nobody[i+5]<<5).any())
            values++;
        //.O.OOX
        if((nobody[i] & map[i+1] & nobody[i+2] & map[i+3] & map[i+4] & other[i+5]).any())
            values++;
        if((nobody[i] & map[i+1]>>1 & nobody[i+2]>>2 & map[i+3]>>3 & map[i+4]>>4 & other[i+5]>>5).any())
            values++;
        if((nobody[i] & map[i+1]<<1 & nobody[i+2]<<2 & map[i+3]<<3 & map[i+4]<<4 & other[i+5]<<5).any())
            values++;
        //XOO.O.
        if((other[i] & map[i+1] & map[i+2] & nobody[i+3] & map[i+4] & nobody[i+5]).any())
            values++;
        if((other[i] & map[i+1]>>1 & map[i+2]>>2 & nobody[i+3]>>3 & map[i+4]>>4 & nobody[i+5]>>5).any())
            values++;
        if((other[i] & map[i+1]<<1 & map[i+2]<<2 & nobody[i+3]<<3 & map[i+4]<<4 & nobody[i+5]<<5).any())
            values++;
        //.OO.OX
        if((other[i] & map[i+1] & nobody[i+2] & map[i+3] & map[i+4] & nobody[i+5]).any())
            values++;
        if((other[i] & map[i+1]>>1 & nobody[i+2]>>2 & map[i+3]>>3 & map[i+4]>>4 & nobody[i+5]>>5).any())
            values++;
        if((other[i] & map[i+1]<<1 & nobody[i+2]<<2 & map[i+3]<<3 & map[i+4]<<4 & nobody[i+5]<<5).any())
            values++;
        //XO.OO.
        if((other[i] & map[i+1] & nobody[i+2] & map[i+3] & map[i+4] & nobody[i+5]).any())
            values++;
        if((other[i] & map[i+1]>>1 & nobody[i+2]>>2 & map[i+3]>>3 & map[i+4]>>4 & nobody[i+5]>>5).any())
            values++;
        if((other[i] & map[i+1]<<1 & nobody[i+2]<<2 & map[i+3]<<3 & map[i+4]<<4 & nobody[i+5]<<5).any())
            values++;
        //O..OO
        if((map[i] & nobody[i+1] & nobody[i+2] & map[i+3] & map[i+4]).any())
            values++;
        if((map[i] & nobody[i+1]>>1 & nobody[i+2]>>2 & map[i+3]>>3 & map[i+4]>>4).any())
            values++;
        if((map[i] & nobody[i+1]<<1 & nobody[i+2]<<2 & map[i+3]<<3 & map[i+4]<<4).any())
            values++;
        //O.O.O
        if((map[i] & nobody[i+1] & map[i+2] & nobody[i+3] & map[i+4]).any())
            values++;
        if((map[i] & nobody[i+1]>>1 & map[i+2]>>2 & nobody[i+3]>>3 & map[i+4]>>4).any())
            values++;
        if((map[i] & nobody[i+1]<<1 & map[i+2]<<2 & nobody[i+3]<<3 & map[i+4]<<4).any())
            values++;
        //X.OOO.X
        if((other[i] & nobody[i+1] & map[i+2] & map[i+3] & map[i+4] & nobody[i+5] & other[i+6]).any())
            values++;
        if((other[i] & nobody[i+1]>>1 & map[i+2]>>2 & map[i+3]>>3 & map[i+4]>>4 & nobody[i+5]>>5 & other[i+6]>>6).any())
            values++;
        if((other[i] & nobody[i+1]<<1 & map[i+2]<<2 & map[i+3]<<3 & map[i+4]<<4 & nobody[i+5]<<5 & other[i+6]<<6).any())
            values++;

        for(int j=0;j<15;j++){
            if(((map[j]>>i)&=0b001110) ==0b001110 && ((nobody[j]>>i)&=0b110000) ==0b110000 && ((other[j]>>i)&=0b000001) ==0b000001)
                values++;
            if(((map[j]>>i)&=0b011100) ==0b011100 && ((nobody[j]>>i)&=0b000011) ==0b000011 && ((other[j]>>i)&=0b100000) ==0b100000)
                values++;
            if(((map[j]>>i)&=0b010110) ==0b010110 && ((nobody[j]>>i)&=0b101000) ==0b101000 && ((other[j]>>i)&=0b000001) ==0b000001)
                values++;
            if(((map[j]>>i)&=0b011010) ==0b011010 && ((nobody[j]>>i)&=0b000101) ==0b000101 && ((other[j]>>i)&=0b100000) ==0b100000)
                values++;
            if(((map[j]>>i)&=0b011010) ==0b011010 && ((nobody[j]>>i)&=0b100100) ==0b100100 && ((other[j]>>i)&=0b000001) ==0b000001)
                values++;
            if(((map[j]>>i)&=0b010110) ==0b010110 && ((nobody[j]>>i)&=0b001001) ==0b001001 && ((other[j]>>i)&=0b100000) ==0b100000)
                values++;
            if(((map[j]>>i)&=0b10011) ==0b10011 && ((nobody[j]>>i)&=0b01100) ==0b01100)
                values++;
            if(((map[j]>>i)&=0b10101) ==0b10101 && ((nobody[j]>>i)&=0b01010) ==0b01010)
                values++;
            if(((map[j]>>i)&=0b0011100) ==0b0011100 && ((nobody[j]>>i)&=0b0100010) ==0b0100010 && ((other[j]>>i)&=0b1000001) ==0b1000001)
                values++;
        }
    }
    return values;
}

int live_2(Min_min_B map,Min_min_B nobody){
    int values=0;
    for(int i=0;i<11;i++){
        //..OO..
        if((nobody[i] & nobody[i+1] & map[i+2] & map[i+3] & nobody[i+4] & nobody[i+5]).any())
            values++;
        if((nobody[i] & nobody[i+1]>>1 & map[i+2]>>2 & map[i+3]>>3 & nobody[i+4]>>4 & nobody[i+5]>>5).any())
            values++;
        if((nobody[i] & nobody[i+1]<<1 & map[i+2]<<2 & map[i+3]<<3 & nobody[i+4]<<4 & nobody[i+5]<<5).any())
            values++;
        //.O.O.
        if((nobody[i] & map[i+1] & nobody[i+2] & map[i+3] & nobody[i+4]).any())
            values++;
        if((nobody[i] & map[i+1]>>1 & nobody[i+2]>>2 & map[i+3]>>3 & nobody[i+4]>>4).any())
            values++;
        if((nobody[i] & map[i+1]<<1 & nobody[i+2]<<2 & map[i+3]<<3 & nobody[i+4]<<4).any())
            values++;
        //.O..O
        if((nobody[i] & map[i+1] & nobody[i+2] & nobody[i+3] & map[i+4]).any())
            values++;
        if((nobody[i] & map[i+1]>>1 & nobody[i+2]>>2 & nobody[i+3]>>3 & map[i+4]>>4).any())
            values++;
        if((nobody[i] & map[i+1]<<1 & nobody[i+2]<<2 & nobody[i+3]<<3 & map[i+4]<<4).any())
            values++;
        //O..O.
        if((map[i] & nobody[i+1] & nobody[i+2] & map[i+3] & nobody[i+4]).any())
            values++;
        if((map[i] & nobody[i+1]>>1 & nobody[i+2]>>2 & map[i+3]>>3 & nobody[i+4]>>4).any())
            values++;
        if((map[i] & nobody[i+1]<<1 & nobody[i+2]<<2 & map[i+3]<<3 & nobody[i+4]<<4).any())
            values++;


        for(int j=0;j<15;j++){
            if(((map[j]>>i)&=0b001100) ==0b001100 && ((nobody[j]>>i)&=0b110011) ==0b110011)
                values++;
            if(((map[j]>>i)&=0b01010) ==0b01010 && ((nobody[j]>>i)&=0b10101) ==0b10101)
                values++;
            if(((map[j]>>i)&=0b01001) ==0b01001 && ((nobody[j]>>i)&=0b10110) ==0b10110)
                values++;
            if(((map[j]>>i)&=0b10010) ==0b10010 && ((nobody[j]>>i)&=0b01101) ==0b01101)
                values++;
        }
    }
    return values;
}

int sleep_2(Min_min_B map,Min_min_B nobody,Min_min_B other){
    int values=0;
    for(int i=0;i<11;i++){
        //...OOX
        if((nobody[i] & nobody[i+1] & nobody[i+2] & map[i+3] & map[i+4] & other[i+5]).any())
            values++;
        if((nobody[i] & nobody[i+1]>>1 & nobody[i+2]>>2 & map[i+3]>>3 & map[i+4]>>4 & other[i+5]>>5).any())
            values++;
        if((nobody[i] & nobody[i+1]<<1 & nobody[i+2]<<2 & map[i+3]<<3 & map[i+4]<<4 & other[i+5]<<5).any())
            values++;
        //XOO...
        if((other[i] & map[i+1] & map[i+2] & nobody[i+3] & nobody[i+4] & nobody[i+5]).any())
            values++;
        if((other[i] & map[i+1]>>1 & map[i+2]>>2 & nobody[i+3]>>3 & nobody[i+4]>>4 & nobody[i+5]>>5).any())
            values++;
        if((other[i] & map[i+1]<<1 & map[i+2]<<2 & nobody[i+3]<<3 & nobody[i+4]<<4 & nobody[i+5]<<5).any())
            values++;
        //..O.OX
        if((nobody[i] & nobody[i+1] & map[i+2] & nobody[i+3] & map[i+4] & other[i+5]).any())
            values++;
        if((nobody[i] & nobody[i+1]>>1 & map[i+2]>>2 & nobody[i+3]>>3 & map[i+4]>>4 & other[i+5]>>5).any())
            values++;
        if((nobody[i] & nobody[i+1]<<1 & map[i+2]<<2 & nobody[i+3]<<3 & map[i+4]<<4 & other[i+5]<<5).any())
            values++;
        //XO.O..
        if((other[i] & map[i+1] & nobody[i+2] & map[i+3] & nobody[i+4] & nobody[i+5]).any())
            values++;
        if((other[i] & map[i+1]>>1 & nobody[i+2]>>2 & map[i+3]>>3 & nobody[i+4]>>4 & nobody[i+5]>>5).any())
            values++;
        if((other[i] & map[i+1]<<1 & nobody[i+2]<<2 & map[i+3]<<3 & nobody[i+4]<<4 & nobody[i+5]<<5).any())
            values++;
        //.O..OX
        if((nobody[i] & map[i+1] & nobody[i+2] & nobody[i+3] & map[i+4] & other[i+5]).any())
            values++;
        if((nobody[i] & map[i+1]>>1 & nobody[i+2]>>2 & nobody[i+3]>>3 & map[i+4]>>4 & other[i+5]>>5).any())
            values++;
        if((nobody[i] & map[i+1]<<1 & nobody[i+2]<<2 & nobody[i+3]<<3 & map[i+4]<<4 & other[i+5]<<5).any())
            values++;
        //XO..O.
        if((other[i] & map[i+1] & nobody[i+2] & nobody[i+3] & map[i+4] & nobody[i+5]).any())
            values++;
        if((other[i] & map[i+1]>>1 & nobody[i+2]>>2 & nobody[i+3]>>3 & map[i+4]>>4 & nobody[i+5]>>5).any())
            values++;
        if((other[i] & map[i+1]<<1 & nobody[i+2]<<2 & nobody[i+3]<<3 & map[i+4]<<4 & nobody[i+5]<<5).any())
            values++;
        //O...O
        if((map[i] & nobody[i+1] & nobody[i+2] & nobody[i+3] & map[i+4]).any())
            values++;
        if((map[i] & nobody[i+1]>>1 & nobody[i+2]>>2 & nobody[i+3]>>3 & map[i+4]>>4).any())
            values++;
        if((map[i] & nobody[i+1]<<1 & nobody[i+2]<<2 & nobody[i+3]<<3 & map[i+4]<<4).any())
            values++;

        for(int j=0;j<15;j++){
            if(((map[j]>>i)&=0b000110) ==0b000110 && ((nobody[j]>>i)&=0b111000) ==0b111000 && ((other[j]>>i)&=0b000001) ==0b000001)
                values++;
            if(((map[j]>>i)&=0b011000) ==0b011000 && ((nobody[j]>>i)&=0b000111) ==0b000111 && ((other[j]>>i)&=0b100000) ==0b100000)
                values++;
            if(((map[j]>>i)&=0b001010) ==0b001010 && ((nobody[j]>>i)&=0b110100) ==0b110100 && ((other[j]>>i)&=0b000001) ==0b000001)
                values++;
            if(((map[j]>>i)&=0b010100) ==0b010100 && ((nobody[j]>>i)&=0b001011) ==0b001011 && ((other[j]>>i)&=0b100000) ==0b100000)
                values++;
            if(((map[j]>>i)&=0b010010) ==0b010010 && ((nobody[j]>>i)&=0b101100) ==0b101100 && ((other[j]>>i)&=0b000001) ==0b000001)
                values++;
            if(((map[j]>>i)&=0b010010) ==0b010010 && ((nobody[j]>>i)&=0b001101) ==0b001101 && ((other[j]>>i)&=0b100000) ==0b100000)
                values++;
            if(((map[j]>>i)&=0b10001) ==0b10001 && ((nobody[j]>>i)&=0b01110) ==0b01110)
                values++;
        }
    }
    return values;
}

int Thing::values(){
    Min_min_B my_map=map[this->player];
    Min_min_B other_map=map[3-this->player];
    Min_min_B nobody=map[0];
    int values=0;
    int reduce=0;
    int v=0;

    if(continuous_5(my_map)) values=9999999;
    if(continuous_4(my_map,nobody)) values=999999;
    if(v=die_4(my_map,nobody,other_map)) values=1000*v;
    if(v=live_3(my_map,nobody)) values=499*v;
    if(v=sleep_3(my_map,nobody,other_map)) values=230*v;;
    if(v=live_2(my_map,nobody)) values=75*v;
    if(v=sleep_2(my_map,nobody,other_map)) values=30*v;

    if(continuous_5(other_map)) reduce=9999999;
    if(continuous_4(other_map,nobody)) reduce=999999;
    if(v=die_4(other_map,nobody,my_map)) reduce=1000*v;
    if(v=live_3(other_map,nobody)) reduce=499*v;
    if(v=sleep_3(other_map,nobody,my_map)) reduce=230*v;;
    if(v=live_2(other_map,nobody)) reduce=75*v;
    if(v=sleep_2(other_map,nobody,my_map)) reduce=30*v;

    return values-reduce;

}

Game Thing::look_id(){
    if(this->id==Dont_kown){
        Min_min_B people=map[3 - (this->player)];
        if(this->behavior.empty())
            this->id=Tie;
        else if(continuous_5(people))
            this->id=Lose;
        else
            this->id=Still;
    }
    return this->id;
}

Thing::Thing(The_Board board,int player): map(board),player(player){
    behavior=this->The_behavior();
}

vector<Point> Thing::The_behavior(){
    vector<Point> moves;
    Min_min_B have_inside;
    int flag=0;

    for(auto e:to_move){
        if(!map[0][e.x][e.y]){
            flag=1;         //確定棋盤上是有棋的
            for(auto beside:Beside){
                int new_x=e.x+beside[0];
                int new_y=e.y+beside[1];
                if(new_x>=0 && new_y>=0 &&  new_x<15 && new_y<15 && !have_inside[new_x][new_y] && map[0][new_x][new_y]){
                    have_inside[new_x][new_y]=1;
                    moves.push_back(Point(new_x,new_y));
                }
            }
        }
    }

    //都沒有棋棋~第一顆棋放中間
    if(!flag) moves.push_back(Point(7.5,7.5));

    return moves;    
}

Thing* Thing::The_nextone(Point mov){
    vector<Point> moves;
    Min_min_B have_inside;

    for(Point e:this->behavior){
        if(e!=mov){
            have_inside[mov.x][mov.y]=1;
            moves.push_back(mov);
        }
    }
 
    for(auto beside:Beside){
        int new_x=mov.x+beside[0];
        int new_y=mov.y+beside[1];
        if(new_x>=0 && new_y>=0 &&  new_x<15 && new_y<15 && !have_inside[new_x][new_y] && map[0][new_x][new_y]){
            have_inside[new_x][new_y]=1;
            moves.push_back(Point(new_x,new_y));
        }
    }

    Thing *nextone= new Thing();
    nextone->map=this->map;
    nextone->player=3-this->player;
    nextone->map[3-nextone->player][mov.x][mov.y]=1;
    nextone->map[0][mov.x][mov.y]=1;
    nextone->behavior=moves;

    return nextone;
}

//----------minimax.cpp----------//

int Minimax::values(Thing* status,int th){
    Game demon=status->look_id();
    if(th==0){
        return status->values();
    }
    if(demon==Tie){
        delete status;
        return 0;
    }
    if(demon==Lose){
        delete status;
        return INT_MIN;
    }

    int value=INT_MIN;
    for(Point e:status->behavior){
        if(-values(status->The_nextone(e),th-1) > value){
            value=status->values();
        }
    }

}

Point Minimax::moving(Thing* status,int th){
    Point origin=Point(15,15);
    int value=INT_MIN;

    for(Point e:status->behavior){
        int nn=-values(status->The_nextone(e),th-1);
        if(nn > value){
            origin=e;
            value=status->values();
        }
    }

    return origin;
};

//----------origin.cpp----------//

Thing o_one;
void read_board(std::ifstream& fin) {
    The_Board board;
    int player;
    fin >> player;
    for (int i = 0; i < SIZE; i++) {
        for (int j = 0; j < SIZE; j++) {
            board[0][i][j]=board[1][i][j]=board[2][i][j]=0;
            int cat;
            fin>>cat;
            board[cat][i][j]=1;
        }
    }

    o_one=Thing(board,player);
}

void write_valid_spot(std::ofstream& fout) {
    auto hell=o_one.behavior;
    for(auto e:hell){
        if(o_one.The_nextone(e)->look_id()==Lose){
            fout << e.x << " " << e.y << endl;
        }
    }
    if(hell.empty()) return;
    int x, y;
    // Keep updating the output until getting killed.
    while(true) {
        auto new_one=Minimax::moving(&o_one,1);
        if (new_one.x!=15 && new_one.y!=15) {
            fout << new_one.x << " " << new_one.y << endl;
            // Remember to flush the output to ensure the last action is written to file.
            fout.flush();
        }
    }
}

int main(int, char** argv) {
    ifstream fin(argv[1]);
    ofstream fout(argv[2]);
    start();
    read_board(fin);
    write_valid_spot(fout);
    fin.close();
    fout.close();
    return 0;
}