cyphesis/rulesets/basic/mind/compass.py
Al Riddoch 003dcfbcc3 2004-01-09 Al Riddoch <alriddoch@zepler.org>
* rulesets/Py_Vector3D.cpp: Add print handler for Vector3D, which
	  doesn't seem to work yet.

	* rulesets/basic/mind/panlingua/interlinguish.py: Add tell verb.
	  Modify regexs for simple sentences so they tolerate more
	  variation in the structure.

	* rulesets/basic/mind/compass.py: New function to convert direction
	  vector into a compass direction string.

	* rulesets/basic/mind/NPCMind.py: Add handler for tell verb, to
	  query knowledge from NPCs.
2005-01-09 01:16:16 +00:00

25 lines
867 B
Python

# This file may be redistributed and modified only under the terms of
# the GNU General Public License (See COPYING for details).
# Copyright (C) 2005 Alistair Riddoch
from Vector3D import Vector3D
compass_points=[(Vector3D(1,0,0), "east"),
(Vector3D(0,1,0), "north"),
(Vector3D(0,-1,0), "south"),
(Vector3D(-1,0,0), "west"),
(Vector3D(0.707,0.707,0), "north east"),
(Vector3D(-0.707,0.707,0), "north west"),
(Vector3D(0.707,-0.707,0), "south east"),
(Vector3D(-0.707,-0.707,0), "south west")]
def vector_to_compass(direction):
dot=-1
ret="unknown"
dir=direction.unit_vector()
for point in compass_points:
new_dot = dir.dot(point[0])
if new_dot > dot:
dot = new_dot
ret = point[1]
return ret