Add tags

Add tags to the following comment

こんにちは。前回投稿した#6205を改造してプレイヤをつくりました。今回は1ソースのお手軽実装です。 元のシステムの流れを変えないようにしながらも幾らか追加点がありますがシステムのコードが長いので省略させていただきます。 で、ベターなほうのプレイヤ同士だと全部引き分けでした。ランダム要素が無いのでしょうがないですね。 あと、盤面の幅は3に依存しています。 あぁ、バグ取りはしましたけど保障はしません。

Result:

Random Player.[103] BetterThinkPlayer.[7210] Draw[2687]

BetterThinkPlayer.[9287] Random Player.[0] Draw[713]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "Player.h"

class BetterPlayer:public Player{//長さ3専用
public:
    char*GetName(){ return "BetterThinkPlayer.";}
    void Play(MBGame& in){
        if(in.HasEmpty() && in.Length()>3) {
            while(in.SetStone(rand()%in.Length(),rand()%in.Length(),Mark_));
            return;
        }
        //マスの重み
        short Point[]={    43,27 ,41,
                        28,100,26,
                        42,29 ,44,
        };
        int op=0;
        do{
            if(!in.HasEmpty()) return;
            think(in,Point,sizeof(Point));
            for(int i=0;i<sizeof(Point);i++){
                if(Point[i] >Point[op]){
                    op=i;
                }
            }
            Point[op]=-10000;
        }while(!in.SetStone(op%3,op/3,Mark_));
        
    }
protected:
    
    void think(MBGame& in,short Point[],int N){
        const short Posi = 10;
        const short Nega = -5;
        const short denger =9999;
        char Lines[8][3]={
                        {0,1,2},{3,4,5},{6,7,8},//横
                        {0,3,6},{1,4,7},{2,5,8},//縦
                        {0,4,8},{2,4,6},//斜め
        };
        char Side[9][9]={    
                        {1,3,-1},//-1は番兵
                        {0,2,4,-1},
                        {1,5,-1},
                        {0,4,6,-1},
                        {0,1,2,3,5,6,7,8,-1},
                        {2,4,8,-1},
                        {3,7,-1},
                        {6,4,8,-1},    
                        {5,7,-1},
        };
        for(int i=0;i<9;i++){//こまの配置による判定
            for(int j=0;Side[i][j]!= -1;j++){
                int x=0,y=0;
                int N = Side[i][j];
                x = N%3;
                y = N/3;
                Mark M= in.At(x,y);
                if(M == Mark_) Point[Side[i][j]]+= Posi;
                if(M != Mark_ && M != None ) Point[Side[i][j]]+= Nega;
            }
        }
        for(int i=0;i<8;i++){//超危ない時の判定
            int P=0;
            int x=0,y=0;
            for(int j=0;j<3;j++){
                int N= Lines[i][j];
                x = N%3;
                y = N/3;
                Mark M = in.At(x,y);
                if(M == Mark_) P++;
                if(M != None && M != Mark_) P--;
            }
            for(int j=0;j<3;j++){
                if(P == 2) Point[Lines[i][j]]+=denger;
                if(P == -2) Point[Lines[i][j]]+=denger;
            }
        }
    }

};

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...