Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
StarCraft-II-AI
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
data-analysis-and-ai
StarCraft-II-AI
Commits
a2d1320a
Commit
a2d1320a
authored
6 years ago
by
Overloadi
Browse files
Options
Downloads
Patches
Plain Diff
Lisätty ensimmäinen toimiva ei-oppiva AI
parents
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
TerranRushAI.py
+173
-0
173 additions, 0 deletions
TerranRushAI.py
with
173 additions
and
0 deletions
TerranRushAI.py
0 → 100644
+
173
−
0
View file @
a2d1320a
### BO: https://lotv.spawningtool.com/build/65735/
import
sc2
from
sc2
import
run_game
,
maps
,
Race
,
Difficulty
from
sc2.constants
import
*
from
sc2.player
import
Bot
,
Computer
,
Human
import
random
class
ThreeRaxBot
(
sc2
.
BotAI
):
def
__init__
(
self
):
self
.
raxmarines
=
[]
self
.
raxmarauders
=
[]
self
.
upgrades
=
[
"
shields
"
,
"
shells
"
,
"
stimpack
"
]
def
select_target
(
self
):
#target = self.known_enemy_structures
#if target.exists:
# return target.random.position
#target = self.known_enemy_units
#if target.exists:
# return target.random.position
#if min([u.position.distance_to(self.enemy_start_locations[0]) for u in self.units]) < 5:
# return self.enemy_start_locations[0].position
#return self.state.mineral_field.random.position
if
len
(
self
.
known_enemy_units
)
>
0
:
return
random
.
choice
(
self
.
known_enemy_units
)
elif
len
(
self
.
known_enemy_structures
)
>
0
:
return
random
.
choice
(
self
.
known_enemy_structures
)
else
:
return
self
.
enemy_start_locations
[
0
]
async
def
on_step
(
self
,
iteration
):
cc
=
self
.
units
(
COMMANDCENTER
)
if
not
cc
.
exists
:
target
=
self
.
known_enemy_structures
.
random_or
(
self
.
enemy_start_locations
[
0
]).
position
for
unit
in
self
.
workers
|
self
.
units
(
MARINE
)
|
self
.
units
(
MARAUDER
):
await
self
.
do
(
unit
.
attack
(
target
))
return
else
:
cc
=
cc
.
first
for
scv
in
self
.
units
(
SCV
).
idle
:
await
self
.
do
(
scv
.
gather
(
self
.
state
.
mineral_field
.
closest_to
(
cc
)))
for
gas
in
self
.
units
(
REFINERY
):
if
gas
.
assigned_harvesters
<
gas
.
ideal_harvesters
:
gasscv
=
self
.
workers
.
closer_than
(
20
,
gas
)
if
gasscv
.
exists
:
await
self
.
do
(
gasscv
.
random
.
gather
(
gas
))
if
self
.
can_afford
(
SCV
)
and
self
.
workers
.
amount
<
19
and
cc
.
noqueue
:
if
cc
.
noqueue
:
await
self
.
do
(
cc
.
train
(
SCV
))
# SUPPLY DEPOTS
if
self
.
supply_used
==
14
or
self
.
supply_used
==
15
and
not
self
.
already_pending
(
SUPPLYDEPOT
):
if
self
.
can_afford
(
SUPPLYDEPOT
):
await
self
.
build
(
SUPPLYDEPOT
,
near
=
cc
.
position
.
towards
(
self
.
game_info
.
map_center
,
8
))
if
self
.
can_afford
(
REFINERY
)
and
not
self
.
already_pending
(
REFINERY
)
and
self
.
supply_used
==
14
:
vgs
=
self
.
state
.
vespene_geyser
.
closer_than
(
20.0
,
cc
)
for
vg
in
vgs
:
if
self
.
units
(
REFINERY
).
closer_than
(
1.0
,
vg
).
exists
:
break
worker
=
self
.
select_build_worker
(
vg
.
position
)
if
worker
is
None
:
break
await
self
.
do
(
worker
.
build
(
REFINERY
,
vg
))
break
elif
self
.
supply_used
==
18
and
not
self
.
already_pending
(
SUPPLYDEPOT
):
if
self
.
can_afford
(
SUPPLYDEPOT
):
await
self
.
build
(
SUPPLYDEPOT
,
near
=
cc
.
position
.
towards
(
self
.
game_info
.
map_center
,
8
))
elif
self
.
supply_used
==
22
and
not
self
.
already_pending
(
SUPPLYDEPOT
):
if
self
.
can_afford
(
SUPPLYDEPOT
):
await
self
.
build
(
SUPPLYDEPOT
,
near
=
cc
.
position
.
towards
(
self
.
game_info
.
map_center
,
8
))
elif
self
.
supply_used
>
23
and
self
.
supply_left
<=
3
:
if
self
.
can_afford
(
SUPPLYDEPOT
)
and
not
self
.
already_pending
(
SUPPLYDEPOT
):
await
self
.
build
(
SUPPLYDEPOT
,
near
=
cc
.
position
.
towards
(
self
.
game_info
.
map_center
,
8
))
# REFINERY
#if self.supply_used == 26 and self.already_pending(REFINERY) == 0:
# if self.can_afford(REFINERY):
# vgs = self.state.vespene_geyser.closer_than(20.0, cc)
# for vg in vgs:
# if self.units(REFINERY).closer_than(1.0, vg).exists:
# break
#
# worker = self.select_build_worker(vg.position)
# if worker is None:
# break
#
# await self.do(worker.build(REFINERY, vg))
# break
# 3 Rax, 1 techlab, 2 reactor
if
self
.
supply_used
>=
15
and
self
.
units
(
BARRACKS
).
amount
<
1
:
if
self
.
can_afford
(
BARRACKS
):
await
self
.
build
(
BARRACKS
,
near
=
cc
.
position
.
towards
(
self
.
game_info
.
map_center
,
8
))
if
self
.
supply_used
>=
18
and
self
.
units
(
BARRACKS
).
amount
<
2
:
if
self
.
can_afford
(
BARRACKS
):
await
self
.
build
(
BARRACKS
,
near
=
cc
.
position
.
towards
(
self
.
game_info
.
map_center
,
8
))
if
self
.
supply_used
>=
19
and
self
.
units
(
BARRACKS
).
amount
<
3
:
if
self
.
can_afford
(
BARRACKS
):
await
self
.
build
(
BARRACKS
,
near
=
cc
.
position
.
towards
(
self
.
game_info
.
map_center
,
8
))
if
self
.
supply_used
>=
22
and
self
.
units
(
BARRACKS
).
amount
<
4
:
if
self
.
can_afford
(
BARRACKS
):
await
self
.
build
(
BARRACKS
,
near
=
cc
.
position
.
towards
(
self
.
game_info
.
map_center
,
8
))
# TECHLAB
if
self
.
units
(
BARRACKS
).
ready
.
exists
:
if
not
self
.
units
(
BARRACKSTECHLAB
).
exists
and
not
self
.
already_pending
(
BARRACKSTECHLAB
):
for
rax
in
self
.
units
(
BARRACKS
):
self
.
raxmarauders
.
append
(
rax
)
await
self
.
do
(
rax
.
build
(
BARRACKSTECHLAB
))
# REACTOR
#if self.units(BARRACKS).ready.exists:
# if self.units(BARRACKS).amount > 1 and self.units(BARRACKSREACTOR).amount < 3 and not self.already_pending(BARRACKSREACTOR):
# rax.b
# for rax in self.units(BARRACKS):
# self.raxmarines.append(rax)
# await self.do(rax.build(BARRACKSREACTOR))
# UPGRADES: SHIELD -> CONCUSSIVE SHELL -> STIMPACK
if
len
(
self
.
upgrades
)
!=
0
:
if
self
.
units
(
BARRACKSTECHLAB
).
ready
.
exists
:
techlab
=
self
.
units
(
BARRACKSTECHLAB
).
ready
.
first
if
self
.
can_afford
(
RESEARCH_COMBATSHIELD
)
and
"
shields
"
in
self
.
upgrades
:
await
self
.
do
(
techlab
(
RESEARCH_COMBATSHIELD
))
self
.
upgrades
.
remove
(
"
shields
"
)
shells
=
True
elif
"
shells
"
in
self
.
upgrades
:
if
self
.
can_afford
(
RESEARCH_CONCUSSIVESHELLS
)
and
self
.
units
(
BARRACKSTECHLAB
).
noqueue
:
await
self
.
do
(
techlab
(
RESEARCH_CONCUSSIVESHELLS
))
self
.
upgrades
.
remove
(
"
shells
"
)
elif
"
stimpack
"
in
self
.
upgrades
:
if
self
.
can_afford
(
BARRACKSTECHLABRESEARCH_STIMPACK
)
and
self
.
units
(
BARRACKSTECHLAB
).
noqueue
:
await
self
.
do
(
techlab
(
BARRACKSTECHLABRESEARCH_STIMPACK
))
self
.
upgrades
.
remove
(
"
stimpack
"
)
# TRAIN MARINES MARAUDERS
if
self
.
units
(
BARRACKSTECHLAB
).
exists
and
self
.
can_afford
(
MARAUDER
):
for
rax
in
self
.
units
(
BARRACKS
):
if
rax
.
has_add_on
and
rax
.
noqueue
:
await
self
.
do
(
rax
.
train
(
MARAUDER
))
for
rax
in
self
.
units
(
BARRACKS
):
if
not
rax
.
has_add_on
and
self
.
can_afford
(
MARINE
)
and
rax
.
noqueue
:
await
self
.
do
(
rax
.
train
(
MARINE
))
if
iteration
%
50
==
0
and
self
.
units
(
MARINE
).
amount
>
8
:
target
=
self
.
select_target
()
marauders
=
self
.
units
(
MARAUDER
)
marines
=
self
.
units
(
MARINE
)
if
(
iteration
//
50
)
%
10
==
0
:
for
marine
in
marines
:
await
self
.
do
(
marine
.
attack
(
target
))
for
marauder
in
marauders
:
await
self
.
do
(
marauder
.
attack
(
target
))
else
:
for
marine
in
marines
.
idle
:
await
self
.
do
(
marine
.
attack
(
target
))
for
marauder
in
marauders
.
idle
:
await
self
.
do
(
marauder
.
attack
(
target
))
#if self.units(REACTOR).exists and self.can_afford(MARINE):
# for rax in self.raxmarines:
# if rax.has_add_on and rax.noqueue:
# await self.do(rax.train(MARINE))
botti
=
ThreeRaxBot
()
run_game
(
maps
.
get
(
"
CatalystLE
"
),
[
Bot
(
Race
.
Terran
,
botti
),
Computer
(
Race
.
Zerg
,
Difficulty
.
Hard
)],
realtime
=
False
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment