GithubHelp home page GithubHelp logo

alien's Introduction

Overview

I broke this project into 2 basic parts, an atlas (map is a reserved word), and a 'battle'. The atlas is a map of city names onto structs. Each struct has 4 pointers, N S E and W, and they point to cities in their respective directions. The 'battle' is a slice containing pointers to warzone structs. Each warzone contains the ID of any aliens in it and a pointer to the city being attacked. Warzones are updated every time an alien enters a city, and the atlas is updated every time a city is destroyed.

Getting started

Here is a really simple controller function you can use to simulate the attack. Wherever this is being invoked from needs to have the input file.

package main

import "github.com/jamesonev/alien"

func main() {
	alien.Attack()
}

You can run this with go run main.go 5, with however many aliens you want. You also have the option to specify an input file for the program as the final argument in the command line. If no file is specified, the program will look for a file named input.txt in the current directory.

At the end, Attack prints the current atlas including any roads between cities. It also does a check of all remaining cities for aliens and prints out the location and number of any found, which is helpful for checking the correctness of the implementation

Development process

This is my first Go project, and so it had quite a steep learning curve. Conceptually, I'm used to separating my code into .c/.h files and linking them in a makefile, so transitioning into thinking in terms of packages was challenging. You can see that I tried to use good cohesion/coupling practices, like how atlas.go has no knowledge of the battle. However, figuring out the most elegant way to do that in a package was challenging.

Other

One thing that may appear to be a bug is that if 2 aliens are in adjacent cities that are only linked to each other, they will constantly switch cities without ever meeting to fight. This may appear to be a bug, but its a result of implementing the behavior described in the spec.

alien's People

Contributors

jamesonev avatar

Watchers

James Cloos 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.