Giter VIP home page Giter VIP logo

betterkara's Introduction

What does this script provide you?

This script enables you to use an easier API for the PythonKara Project. You can use commands like kara.is_tree_left(), kara.is_mushroom_back() or kara.left(4) which helps you writing code easier.

Quickstart

Copy the code of betterkara.py and paste it into your file. Some variables are overwritten, these provide you the better API.

Examples

# The copy-pasted code...  
  
# Sets leafs until Kara hits a tree  
while not kara.is_tree_front():  
    kara.set_leaf()  
    kara.forward()  
  
  
# If a mushroom is behind Kara, he will be moved behind it  
if kara.is_mushroom_back():  
    kara.left()  
    kara.back(2)  
    kara.right()  
  
  
# Moves Kara to the next hole on the left side  
while True:  
    if not kara.is_empty_left():  
        kara.forward()  
    else:  
        kara.left()  
  
  
# Lets Kara fill out a closed figure with leafs  
def move_and_set_leaves():
    # type: () -> int
    # noinspection PyShadowingNames
    counter = 0
    
    while True:
        # Blatt setzen
        kara.set_leaf()
        
        # Überprüfen
        if not kara.is_tree_front():
            kara.forward()
            counter += 1
        else:
            break
    
    # Wieder zurückgehen
    kara.backward(counter)
    
    return counter


while True:  # Do-While
    if not kara.is_tree_front():
        if kara.is_tree_left():
            # Tree is left, fill out everything on the right
            kara.turn_right()
            move_and_set_leaves()
            kara.turn_left()
            
            # Forward for next step
            kara.forward()
        else:
            # No tree front, fill out everything there
            move_and_set_leaves()
            
            # To left for next step
            kara.turn_left()
            kara.forward()
    else:
        # To the left if there is not tree
        if not kara.is_tree_left():
            kara.turn_left()
            kara.forward()
        else:
            # No way there, turn around
            kara.turn_around()
    
    if kara.current_position() == start_position:  # Do-While
        # Kara is on start position
        break
  
  
# Moves Kara out of a maze  
while not kara.is_on_leaf():  
    if kara.is_tree_left():  
        if kara.is_tree_front():  
            kara.turn_right()  
    else:  
        kara.turn_left()  
      
    kara.forward()

Code

Main classes

Kara

Attributes

Value Description
instance The "old" kara instance
view The view handler (handles the current view of Kara)
position The relative position handler (handles the current position of Kara)

Methods

Move functions will automatically check for trees, etc. If there is an immovable object in the way, Kara won't be moved.

Value Description Parameters Return
Rotate
turn_left, turn_right Turns Kara to the left - None
turn_around Turns Kara around - None
Move
forward backward left right Moves Kara x steps to the correlating direction amount - The amount of steps that should be moved None
absolute_up Moves Kara x steps up, not relative to Kara but to the grid amount - The amount that should be moved None
absolute_down Moves Kara x steps down, not relative to Kara but to the grid amount - The amount that should be moved None
absolute_left Moves Kara x steps left, not relative to Kara but to the grid amount - The amount that should be moved None
absolute_right Moves Kara x steps right, not relative to Kara but to the grid amount - The amount that should be moved None
Sensors
is_tree_front is_tree_back is_tree_left is_tree_right Checks whether a tree at this side of Kara - bool - Whether there is a tree
is_leaf_front is_leaf_back is_leaf_left is_leaf_right Checks whether a leaf at this side of Kara - bool - Whether there is a leaf
is_on_leaf Checks whether Kara is on a leaf - bool - Whether Kara is on leaf
is_mushroom_front is_mushroom_back is_mushroom_left is_mushroom_right Checks whether a mushroom at this side of Kara - bool - Whether there is a mushroom
is_empty_front is_empty_back is_empty_left is_empty_right Checks whether the side is empty - bool - Whether there is nothing
Handlers
set_leaf remove_leaf Sets/Removes a leaf - bool - Whether the leaf got placed/removed
swap_leaf Swaps the leaf, i.e. Kara is on leaf -> removes it, - bool - Whether the leaf got placed/removed

betterkara's People

Contributors

myzel394 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.