This repository has been archived by the owner on Jul 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.ps1
114 lines (101 loc) · 2.45 KB
/
bot.ps1
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
102
103
104
105
106
107
108
109
110
111
112
113
114
git -C '../gitland' pull
$players = Get-ChildItem -Path '../gitland/players/' -Exclude 'placeholder99999999999999999999999999999' `
| ForEach-Object {
@{
Player = $_.Name
Team = Get-Content ($_.FullName+'/team')
X = Get-Content ($_.FullName+'/x')
Y = Get-Content ($_.FullName+'/y')
}
}
$y = 0
$decay = Get-Content -Path '../gitland/decay' `
| ForEach-Object {
$x = 0
$_ -split ',' | ForEach-Object {
@{
Decay = $_
X = $x++
Y = $y
}
}
$y++
}
$y = 0
$map = Get-Content -Path '../gitland/map' `
| ForEach-Object {
$x = 0
$_ -split ',' | ForEach-Object {
@{
Color = $_
Decay = $decay `
| Where-Object X -eq $x `
| Where-Object Y -eq $y `
| Select-Object -ExpandProperty Decay
X = $x
Y = $y
}
$x++
}
$y++
}
$directionList = @(
@{
Name = 'up'
Axis = 'Y'
Modifier = -1
}
@{
Name = 'down'
Axis = 'Y'
Modifier = 1
}
@{
Name = 'left'
Axis = 'X'
Modifier = -1
}
@{
Name = 'right'
Axis = 'X'
Modifier = 1
}
)
$currentPlayer = $players | Where-Object Player -eq 'lub'
$currentPosition = $map `
| Where-Object X -eq $currentPlayer.X `
| Where-Object Y -eq $currentPlayer.Y
$moveList = $directionList | ForEach-Object {
$preMove = $currentPosition.Clone()
[int]$preMove.($_.Axis) += $_.Modifier
$position = $map `
| Where-Object X -eq $preMove.X `
| Where-Object Y -eq $preMove.Y
# check for $null, because that's out of bounds
if($position -ne $null) {
$move = $position.Clone()
$move.Direction = $_.Name
# check if player is currently empty
# TODO: spy on move of player on that field
if($move.Color[0] -eq 'u') {
[pscustomobject]$move
}
}
} `
| Sort-Object {$_.Color[1] -ne $currentPlayer.Team[1]},{$_.Color -ne 'ux'},Decay -Descending
'possible moves:'
$moveList | Format-Table
if($moveList) {
$action = $moveList | Select-Object -First 1
'choosen action:'
$action | Format-Table
$direction = $action.Direction
} else {
$direction = $directionList.Name | Get-Random
'no suitable move found; moving random: '+$direction
}
$direction | Out-File -FilePath act
$env:GIT_SSH_COMMAND = 'ssh -i ./ssh'
git add act
git commit -m 'act'
git push