Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

71%
+3 −0
Challenges Three Number Monte

MoshiBot from numpy.polynomial import Polynomial def MoshiBot(data, history): if len(history) < 10: return [180, 180, 0] lastmin = min(history[-1]) lastmid = sorted(history[-1])[1] ...

posted 3y ago by Moshi‭

Answer
#1: Initial revision by user avatar Moshi‭ · 2021-07-30T04:28:49Z (over 3 years ago)
## MoshiBot

```python
from numpy.polynomial import Polynomial
def MoshiBot(data, history):
	if len(history) < 10:
		return [180, 180, 0]

	lastmin = min(history[-1])
	lastmid = sorted(history[-1])[1]
	projectedmin = lastmin
	projectedmid = lastmid

	if len(history) >= 10:
		cutoff = len(history) - 10
		snapshot = history[cutoff:]
		minvalues = list(map(min, snapshot))
		midvalues = list(map(lambda vals: sorted(vals)[1], snapshot))
		
		xpoints = range(cutoff, cutoff + len(snapshot))
		minprojection = Polynomial.fit(xpoints, minvalues, deg=2)
		midprojection = Polynomial.fit(xpoints, midvalues, deg=2)

		projectedmin = minprojection(len(history))
		projectedmid = midprojection(len(history))

	safemin = max(0, min(360, math.ceil(projectedmin + 1)))

	if safemin >= 180:
		# The model broke down
		return [180, 180, 0]
	
	mid = math.floor(180 - safemin / 2)
	
	if mid > projectedmid:
		return [safemin, mid, 360 - safemin - mid]
	else:
		mid = max(safemin, min(360 - safemin, math.ceil(projectedmid + 1)))
		return [safemin, mid, 360 - safemin - mid]
```

Attempts to predict the opponents next move using a regressive model.