Skip to content

Commit f36dd1c

Browse files
committed
Edits to method names.
1 parent 943a36c commit f36dd1c

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A Python module for programming turtle robots to compete against each other in a
44

55
_Combat Turtles_ is meant as a learning tool for intermediate-level [Python](https://www.python.org/) students. It defines a combat game in which programmable [turtle robots](https://en.wikipedia.org/wiki/Turtle_(robot)) move around a battlefield firing missiles to destroy each other. A parent class, `TurtleParent`, defines a variety of basic attributes and methods for these turtle robots, and an `ai/` folder contains a variety of subclasses of this parent class which define different turtle AIs. The main driver script `combatturtles.py` loads selected AI subclasses to compete against each other in combat.
66

7-
The player can create their own turtle AIs by extending the `TurtleParent` class and overwriting a few key methods. The game is run using discrete step events (at a rate of approximately 30 steps/second), with each turtle defining its actions on a per-step basis. Custom AI submodules (in the form of standalone `.py` files) can be added to the `ai/` directory to import the player's AI into the game. Several example and template subclasses are included in this directory to get the player started. See also the [documentation below](#instructions) for a detailed guide to writing custom AIs. Python students might enjoy competing against each other to see whom can come up with the best AI, while Python instructors might consider running a class tournament to encourage students to learn more about object-oriented programming.
7+
The player can create their own turtle AIs by extending the `TurtleParent` class and overwriting a few key methods. The game is run using discrete step events (at a rate of approximately 30 steps/second), with each turtle defining its actions on a per-step basis. Custom AI submodules (in the form of standalone `.py` files) can be dropped into the `ai/` directory to import the player's AI into the game. Several example and template subclasses are included in this directory to get the player started. See also the [documentation below](#instructions) for a detailed guide to writing custom AIs. Python students might enjoy competing against each other to see whom can come up with the best AI, while Python instructors might consider running a class tournament to encourage students to learn more about object-oriented programming.
88

99
**This is a work in progress.** I am still in the process of adding features and fixing bugs, but if you are interested in playing with the latest public beta, please see the [releases](https://github.com/adam-rumpf/combat-turtles/releases) page.
1010

@@ -253,16 +253,16 @@ The following is a list of methods which return information about the current st
253253
* `self.relative_position([target])` -- Calculates the relative position from this turtle to a target coordinate (px, px), meaning the change in this turtle's position required to reach the target coordinate.
254254
If given no argument, the opponent's position is used.
255255
Aliases: `relative_position`, `relpos`
256-
* `self.relative_heading([target])` -- Calculates the heading from this turtle to a target coordinate (deg), meaning the direction required to move from this turtle's position to the target coordinate. Headings are normalized to the interval `(-180,180]` with `0` indicating east, `90` indicating north, `180` indicating west, and `-90` indicating south.
256+
* `self.heading_towards([target])` -- Calculates the heading from this turtle to a target coordinate (deg), meaning the direction required to move from this turtle's position to the target coordinate. Headings are normalized to the interval `(-180,180]` with `0` indicating east, `90` indicating north, `180` indicating west, and `-90` indicating south.
257257
Similar to `self.relative_heading_towards()`, but does not take this turtle's current heading into consideration.
258258
If given no argument, the opponent's position is used.
259-
Aliases: `relative_heading`, `relhead`
259+
Aliases: `heading_towards`, `heading_toward`, `towards`, `toward`
260260
* `self.relative_heading_towards([target])` -- Calculates the change in heading required to turn this turtle to face a target coordinate (deg), meaning the minimum angle that this turtle would need to turn in order to face the target. Positive headings indicate counterclockwise turning while negative headings indicate clockwise turning.
261-
Similar to `self.relative_heading()`, but gives a heading relative to this turtle's current heading.
261+
Similar to `self.heading_towards()`, but gives a heading relative to this turtle's current heading.
262262
If given no argument, the opponent's position is used.
263-
Aliases: `relative_heading_towards`, `relative_heading_toward`, `towards`, `toward`
263+
Aliases: `relative_heading_towards`, `relative_heading_toward`
264264
* `self.free_space(coord)` -- Determines whether or not the given coordinate is free of obstacles (`True` if inside the arena and free of obstacles, `False` if not). The coordinates for which this returns `True` are exactly the coordinates which turtles and missiles are allowed to occupy.
265265
Aliases: `free_space`, `free`
266-
* `self.line_of_sight([target])` -- Determines whether or not there is a line of sight between this turtle and a target coordinate (`True` if so, `False` if not). A line of sight implies that, if this turtle were to immediately fire a missile while facing the specified coordinate, the missile would travel towards the target without obstruction from any block objects.
266+
* `self.line_of_sight([target])` -- Determines whether or not there is a line of sight between this turtle and a target coordinate (`True` if so, `False` if not). A line of sight implies that, if this turtle were to immediately fire a missile while facing the specified coordinate, the missile would reach the target without obstruction from any block objects.
267267
If given no argument, the opponent's position is used.
268268
Aliases: `line_of_sight`, `los`

ai/_template.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,12 @@ class CombatTurtle(game.tcturtle.TurtleParent):
113113
relative_position([target]) -- returns the relative position of a target
114114
relative to this turtle (px, px) (aliases: relative_position,
115115
relpos)
116-
relative_heading([target]) -- returns the heading from this turtle to a
117-
target (deg) (aliases: relative_heading, relhead)
116+
heading_towards([target]) -- returns the heading from this turtle to a
117+
target (deg) (aliases: heading_towards, heading_toward, towards,
118+
toward)
118119
relative_heading_towards([target]) -- returns the smallest heading change
119120
required to turn this turtle towards a target (deg) (aliases:
120-
relative_heading_twards, relative_heading_toward, towards, toward)
121+
relative_heading_twards, relative_heading_toward)
121122
free_space(coord) -- returns whether a given coordinate is free of
122123
obstacles (aliases: free_space, free)
123124
line_of_sight([target]) -- returns whether there is a direct line of sight

ai/drunken.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
# Title: DrunkenTurtle
44
# Author: Adam Rumpf
5-
# Version: 1.0.1
6-
# Date: 11/13/2020
5+
# Version: 1.1.0
6+
# Date: 11/20/2020
77

88
import math
99
import random
@@ -86,7 +86,7 @@ def step(self):
8686
"""
8787

8888
# Get direction towards opponent and add sinusoidal noise
89-
dir = self.relative_heading()
89+
dir = self.heading_towards()
9090
dir += self.wander_amp*math.sin((2*math.pi*self.time)/self.wander_wl)
9191

9292
# Turn towards the specified heading

game/tcturtle.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ class TurtleParent:
111111
relative_position([target]) -- returns the relative position of a
112112
target relative to this turtle (px, px) (aliases:
113113
relative_position, relpos)
114-
relative_heading([target]) -- returns the heading from this turtle to
115-
a target (deg) (aliases: relative_heading, relhead)
114+
heading_towards([target]) -- returns the heading from this turtle to
115+
a target (deg) (aliases: heading_towards, heading_toward, towards,
116+
toward)
116117
relative_heading_towards([target]) -- returns the smallest heading
117118
change required to turn this turtle towards a target (deg)
118-
(aliases: relative_heading_twards, relative_heading_toward,
119-
towards, toward)
119+
(aliases: relative_heading_twards, relative_heading_toward)
120120
free_space(coord) -- returns whether a given coordinate is free of
121121
obstacles (aliases: free_space, free)
122122
line_of_sight([target]) -- returns whether there is a direct line of
@@ -1618,8 +1618,8 @@ def relative_position(self, target=None):
16181618

16191619
#-------------------------------------------------------------------------
16201620

1621-
def relative_heading(self, target=None):
1622-
"""TurtleParent.relative_heading([target]) -> int
1621+
def heading_towards(self, target=None):
1622+
"""TurtleParent.heading_towards([target]) -> int
16231623
Returns the heading (deg) towards a target coordinate.
16241624
16251625
User visibility:
@@ -1654,7 +1654,9 @@ def relative_heading(self, target=None):
16541654
return int(math.degrees(Angle(math.atan2(-dy, dx))))
16551655

16561656
# Set aliases
1657-
relhead = relative_heading
1657+
heading_toward = heading_towards
1658+
towards = heading_towards
1659+
toward = heading_towards
16581660

16591661
#-------------------------------------------------------------------------
16601662

@@ -1683,15 +1685,13 @@ def relative_heading_towards(self, target=None):
16831685
"""
16841686

16851687
# Calculate absolute heading towards target
1686-
ah = Angle(self.relative_heading(target), "degrees")
1688+
ah = Angle(self.heading_towards(target), "degrees")
16871689

16881690
# Return difference in headings
16891691
return int(ah - self.heading)
16901692

16911693
# Set aliases
16921694
relative_heading_toward = relative_heading_towards
1693-
towards = relative_heading_towards
1694-
toward = relative_heading_towards
16951695

16961696
#-------------------------------------------------------------------------
16971697

@@ -1752,7 +1752,7 @@ def line_of_sight(self, target=None):
17521752
target = self.other_position
17531753

17541754
# Get heading towards target
1755-
rh = math.radians(self.relative_heading(target))
1755+
rh = math.radians(self.heading_towards(target))
17561756

17571757
# Get initial signs of x- and y-direction differences
17581758
sx = self._sign(target[0] - self.x) # x-direction sign

0 commit comments

Comments
 (0)