-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfightAI.m
101 lines (101 loc) · 3.02 KB
/
fightAI.m
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
function [ ] = fightAI( strat, first )
board=[1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1];
d=6;
playing=true;
dispBoard(board,0);
if first==1
while playing
user=input('Make your move:\n(enter "0" to forfeit)\n');
if user==0
point=2+.5*tanh(sum(board))^5;
fprintf('Its a tie, you recieve %1.2f points!\n',point)
return
end
tempboard=board;
branches=validMoves(board);
userEnd=length(user);
tempboard(user(1:userEnd-1))=0;
tempboard(user(userEnd))=board(user(1));
for i= 29:32
if tempboard(i)==1
tempboard(i)=1.5;
end
end
for i=1:size(branches,1)
if tempboard==branches(i,:)
board=branches(i,:);
dispBoard(board,0)
end
end
if tempboard~=board
disp('invalid move. Try again.\n');
continue
end
if isempty(board(board<0))
fprintf('You Win! Your receive 4 points!\n')
return
elseif isempty(board(board>0))
fprintf('You lose! Your receive 0 points!\n')
return
end
board=switchSides(board);
board=showMeWhatYouGot(board, strat, d);
dispBoard(board,1)
board=switchSides(board);
if isempty(board(board<0))
fprintf('You Win! Your receive 4 points!\n')
return
elseif isempty(board(board>0))
fprintf('You lose! Your receive 0 points!\n')
return
end
end
else
while playing
board=switchSides(board);
board=showMeWhatYouGot(board, strat, d);
dispBoard(board,1)
board=switchSides(board);
if isempty(board(board<0))
fprintf('You Win! Your receive 4 points!\n')
return
elseif isempty(board(board>0))
fprintf('You lose! Your receive 0 points!\n')
return
end
user=input('Make your move:\n(enter "0" to forfeit)\n');
if user==0
point=2+.5*tanh(sum(board))^5;
fprintf('Its a tie, you recieve %1.2f points!\n',point)
return
end
tempboard=board;
branches=validMoves(board);
userEnd=length(user);
tempboard(user(1:userEnd-1))=0;
tempboard(user(userEnd))=board(user(1));
for i= 29:32
if tempboard(i)==1
tempboard(i)=1.5;
end
end
for i=1:size(branches,1)
if tempboard==branches(i,:)
board=branches(i,:);
dispBoard(board,0)
end
end
if tempboard~=board
disp('invalid move. Try again.\n');
continue
end
if isempty(board(board<0))
fprintf('You Win! Your receive 4 points!\n')
return
elseif isempty(board(board>0))
fprintf('You lose! Your receive 0 points!\n')
return
end
end
end
end