mirror of
https://github.com/ckaczor/Advent2019.git
synced 2026-02-16 18:46:39 -05:00
Day 13 - Part 2
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
@@ -7,13 +8,15 @@ namespace Advent
|
||||
{
|
||||
public static class Day13
|
||||
{
|
||||
private static Dictionary<Tuple<long, long>, long> _tiles;
|
||||
|
||||
public static void Execute()
|
||||
{
|
||||
var lines = File.ReadAllLines(@".\Day13\input.txt");
|
||||
var lines = File.ReadAllLines(@".\Day13\input2.txt");
|
||||
|
||||
var game = new IntcodeComputer(lines[0], 0);
|
||||
var game = new IntcodeComputer(lines[0], 0, OnInput);
|
||||
|
||||
var tiles = new Dictionary<Tuple<long, long>, long>();
|
||||
_tiles = new Dictionary<Tuple<long, long>, long>();
|
||||
|
||||
while (!game.Halted)
|
||||
{
|
||||
@@ -21,10 +24,78 @@ namespace Advent
|
||||
var y = game.Execute(0);
|
||||
var tile = game.Execute(0);
|
||||
|
||||
tiles[new Tuple<long, long>(x, y)] = tile;
|
||||
_tiles[new Tuple<long, long>(x, y)] = tile;
|
||||
}
|
||||
|
||||
Console.WriteLine(tiles.Values.Count(t => t == 2));
|
||||
var score = _tiles[new Tuple<long, long>(-1, 0)];
|
||||
|
||||
Console.WriteLine(score);
|
||||
|
||||
//Console.WriteLine(_tiles.Values.Count(t => t == 2));
|
||||
}
|
||||
|
||||
private static long OnInput()
|
||||
{
|
||||
//DrawScreen(_tiles);
|
||||
|
||||
var ballPos = _tiles.First(t => t.Value == 4);
|
||||
var paddlePos = _tiles.First(t => t.Value == 3);
|
||||
|
||||
if (ballPos.Key.Item1 > paddlePos.Key.Item1)
|
||||
return 1;
|
||||
|
||||
if (ballPos.Key.Item1 < paddlePos.Key.Item1)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
|
||||
//Console.WriteLine();
|
||||
//Console.WriteLine();
|
||||
//Console.Write("Input: ");
|
||||
|
||||
//var key = Console.ReadKey();
|
||||
|
||||
//if (key.Key == ConsoleKey.LeftArrow)
|
||||
// return -1;
|
||||
|
||||
//if (key.Key == ConsoleKey.RightArrow)
|
||||
// return 1;
|
||||
|
||||
//return 0;
|
||||
}
|
||||
|
||||
private static void DrawScreen(Dictionary<Tuple<long, long>, long> tiles)
|
||||
{
|
||||
foreach (var tile in tiles)
|
||||
{
|
||||
if (tile.Key.Item1 == -1 && tile.Key.Item2 == 0)
|
||||
{
|
||||
Debug.WriteLine($"Score: {tile.Value}");
|
||||
continue;
|
||||
}
|
||||
|
||||
Console.SetCursorPosition((int)tile.Key.Item1, (int)tile.Key.Item2);
|
||||
|
||||
var c = ' ';
|
||||
|
||||
switch (tile.Value)
|
||||
{
|
||||
case 1:
|
||||
c = 'W';
|
||||
break;
|
||||
case 2:
|
||||
c = 'B';
|
||||
break;
|
||||
case 3:
|
||||
c = 'P';
|
||||
break;
|
||||
case 4:
|
||||
c = 'O';
|
||||
break;
|
||||
}
|
||||
|
||||
Console.Write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1
Day13/input2.txt
Normal file
1
Day13/input2.txt
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user