A little cleanup

This commit is contained in:
Brian Buller 2019-12-13 08:51:59 -06:00
parent c06abb613c
commit 74510f9723
1 changed files with 25 additions and 8 deletions

View File

@ -15,7 +15,7 @@ import (
var auto bool
func main() {
progFileName := "input"
progFileName := "finishinput"
if len(os.Args) > 1 && os.Args[1] == "-auto" {
auto = true
@ -26,6 +26,7 @@ func main() {
func play(prog []int) {
p := intcode.NewProgram(prog)
// For part 1, comment out this line
p.SetProgramValueAt(0, 2)
//p.EnableDebug()
maxX, maxY := 0, 0
@ -70,24 +71,26 @@ func play(prog []int) {
for !gotInput {
fmt.Print("Input (vimlike): ")
reader := bufio.NewReader(os.Stdin)
char, _, err := reader.ReadRune()
inp, err := reader.ReadString('\n')
if err != nil {
panic(err)
}
switch char {
case 'h':
inp = strings.TrimSpace(inp)
switch inp {
case "h":
p.Input(-1)
gotInput = true
case 'l':
case "l":
p.Input(1)
gotInput = true
case 'j', 'k':
case "j", "k":
p.Input(0)
gotInput = true
}
}
}
}
//lookForScore(p, score)
switch p.State() {
case intcode.RET_ERR:
panic(p.Error())
@ -98,13 +101,27 @@ func play(prog []int) {
}()
ret := p.Run()
if ret == intcode.RET_DONE {
fmt.Println("DONE")
fmt.Println("DONE:", score)
} else if ret == intcode.RET_ERR {
fmt.Println("ERROR")
}
//part1(screen)
}
func lookForScore(p *intcode.Program, score int) {
var res []int
code := p.GetCode()
for k, v := range code {
if v == score {
res = append(res, k)
}
}
if len(res) == 1 {
fmt.Println("Score Position:", res[0])
os.Exit(0)
}
}
func part1(s map[string]int) {
var cnt int
for _, v := range s {
@ -116,7 +133,7 @@ func part1(s map[string]int) {
}
func printScreen(screen map[string]int, maxX, maxY, score int) {
fmt.Print(helpers.CLEAR_SCREEN)
//fmt.Print(helpers.CLEAR_SCREEN)
fmt.Println("Score:", score)
for y := 0; y <= maxY; y++ {
for x := 0; x <= maxX; x++ {