GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Docs
  • Python Tutorials

This view

  • Original page
  • New address

GeezerVison is showing minecraft.makecode.com — Agent Moves

Skip to main content
About FAQ Projects GitHub
Examples
Super Powers
Mega Jump Flower trail Super Digger Yellow brick road Game Over
Agent
Agent Dig Agent Tower Agent Checkers Agent Wanderer Agent Pyramid Hilbert Fractals
Mobs
Chicken Rain Zombie Pig Cats vs Dogs Rabbit Invasion Bouncing Pigs Bat Cave
Terraforming
1000 TNT Wipe Out Lava Tower Earthquake Pitfall Grid world Lorenz Attractor
Mini Games
Spleef Leap of Faith Gold Stairs TNT Spleef Gladiator Ice Age
Builder
Builder Wall 3D Axis Compass Build a House TNT Cannon
Courses
CS Intro
About
Lessons Blocks Minecraft Authors
Events
Overview Unplugged 1 Unplugged 2 Activity 1 Activity 2 Activity 3 Activity 4 Project
Coordinates
Overview Unplugged 1 Unplugged 2 Activity 1 Activity 2 Activity 3 Project
Variables
Overview Unplugged Activity 1 Activity 2 Activity 3 Activity 4 Project
Iteration
Overview Unplugged 1 Unplugged 2 Activity 1 Activity 2 Activity 3 Activity 4 Project
Conditionals
Overview Unplugged Activity 1 Activity 2 Activity 3 Activity 4 Project
Functions
Overview Unplugged Activity 1 Activity 2 Activity 3 Project
Arrays
Overview Unplugged 1 Unplugged 2 Activity 1 Activity 2 Activity 3 Project
Artificial Intelligence
Overview Unplugged Activity 1 Activity 2 Activity 3 Project
Final Project
Review Guide Project
Reference
Player Blocks Mobs Agent Builder Gameplay Positions Shapes
Blocks
On Start
Loops
repeat for while for of
Logic
if Boolean
Variables
assign change var var
Math JavaScript blocks Custom blocks
Python
Calling Sequencing Variables Operators Statements Functions Classes
JavaScript
Calling Sequencing Variables Operators Statements Functions Types Classes Interfaces Generics
Types
Number String Boolean Array Function
Get setup Blocks Gallery
Miscellaneous
About Support Translate Sharing projects Offline support Save Reset Beta version Home page content
Developers
Command Line Interface Visual Studio Code support Blocks Embed
Tutorials
Chicken rain Agent Moves Agent Build Agent Wall Mega Jump Walk On Water Flower Trail Positions Super Digger Billboard Compass Rose Fast Forward Spleef Leap of faith Gold Stairs Lava Tower Rainbow Beacon Colorful Rainbow Sand Storm Aquarium Leaping Salmon
Python Tutorials
Chicken rain Agent Moves Agent Build Mega Jump Flower Trail Super Digger Billboard Compass Rose Fast Forward Spleef Leap of faith Gold Stairs Lava Tower Sand Storm Aquarium Leaping Salmon
Using Extensions
Castle Builder Roller Coaster Pixel Art Builder
Lessons
Area AI - Part 1 AI - Part 2 Ratio Volcanoes - Part 1 Volcanoes - Part 2 Storyline Story ending Cubic units Gold mine

Agent Moves

Introduction

Get your agent to move. In this tutorial you give your Agent some turns and moves to really dance!

Make your agent dance!

Teleport your Agent

Bring your Agent near you so you can watch it dance. Teleport the Agent to your position but move it forward by 3.

Run the program and look to see that your Agent comes close to your position.

agent.teleport_to_player()
agent.move(FORWARD, 3)

Make a dance move

To make the first dance move, add in an if else. When the condition in the if is true, have the Agent move forward by 1. Otherwise, for else, have the Agent move back by 1.

agent.teleport_to_player()
agent.move(FORWARD, 3)
if True:
    agent.move(FORWARD, 1)
else:
    agent.move(BACK, 1)

Add the dance logic

Add another if else below the previous one. For the case when condition in the if is true, have the Agent turn right. For the else, have the Agent turn to the left.

agent.teleport_to_player()
agent.move(FORWARD, 3)
if True:
    agent.move(FORWARD, 1)
else:
    agent.move(BACK, 1)
if True:
    agent.turn(TurnDirection.RIGHT)
else:
    agent.turn(TurnDirection.LEFT)

Randomize the moves

Well, these moves are fairly predicable. Add some randomness to the Agent's moves. Replace the true in both of the if conditions with a random logic value. Set the condition as a comparison of a random number between 0 and 1. Make the comparison a check to see that the random number is greater than 0.

agent.teleport_to_player()
agent.move(FORWARD, 3)
if randint(0, 1) > 0:
    agent.move(FORWARD, 1)
else:
    agent.move(BACK, 1)
if randint(0, 1) > 0:
    agent.turn(TurnDirection.RIGHT)
else:
    agent.turn(TurnDirection.LEFT)

Add a loop

The Agent can now make one random dance move. Make the Agent really get the moves going by repeating them in a loop. Put the two if else portions of the program in a for loop. Have the loop repeat 25 times.

agent.teleport_to_player()
agent.move(FORWARD, 3)
for index in range(25):
    if randint(0, 1) > 0:
        agent.move(FORWARD, 1)
    else:
        agent.move(BACK, 1)
    if randint(0, 1) > 0:
        agent.turn(TurnDirection.RIGHT)
    else:
        agent.turn(TurnDirection.LEFT)

Slow down the dance!

Wow, that was a fast dance! The Agent can really bust a move. Add a pause to slow the Agent down. Set the pause time to 250 milliseconds.

agent.teleport_to_player()
agent.move(FORWARD, 3)
for index in range(25):
    if randint(0, 1) > 0:
        agent.move(FORWARD, 1)
    else:
        agent.move(BACK, 1)
    if randint(0, 1) > 0:
        agent.turn(TurnDirection.RIGHT)
    else:
        agent.turn(TurnDirection.LEFT)
    loops.pause(250)

Edit this page on GitHub
Edit template of this page on GitHub
Edit template of this page on GitHub

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.