Removed darts.cs

This commit is contained in:
tiagorg 2022-10-21 16:58:49 +01:00
parent dfd6791648
commit 1694ced5f3
2 changed files with 14 additions and 195 deletions

View File

@ -1,132 +0,0 @@
// .NET core 6.0
// This is just a C# version of the python solution:
// https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/fp/aula02/darts.py
namespace Darts
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Introduza as coordenadas (x, y) do dardo.\nRepresentam as posições horizontal e vertical respetivamente.\nAmbas em milimetros.");
Console.Write("X: ");
int x = Convert.ToInt32(Console.ReadLine());
Console.Write("Y: ");
int y = Convert.ToInt32(Console.ReadLine());
double mod = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
if (mod > 170)
{
Console.WriteLine("Fora do alvo.");
Console.ReadKey();
return;
}
if (mod < 12.7)
{
Console.WriteLine("Pontuação: 50 points");
Console.ReadKey();
return;
}
else if (mod < 32)
{
Console.WriteLine("Pontuação: 25 points");
Console.ReadKey();
return;
}
int basePoint = BasePoint(x, y);
if (mod > 99 && mod < 107)
{
Console.WriteLine($"Pontuação: {basePoint * 3} points");
Console.ReadKey();
return;
}
if (mod > 162)
{
Console.WriteLine($"Pontuação: {basePoint * 2} points");
Console.ReadKey();
return;
}
Console.WriteLine($"Pontuação: {basePoint} points");
Console.ReadKey();
return;
}
public static int BasePoint(int x, int y)
{
if (x > 0)
{
if (Math.Abs(y) < x * Math.Tan(Math.PI / 20))
return 6;
else
{
if (y > 0)
{
if (y < x * Math.Tan(3 * Math.PI / 20))
return 13;
if (y < x * Math.Tan(5 * Math.PI / 20))
return 4;
if (y < x * Math.Tan(7 * Math.PI / 20))
return 18;
if (y < x * Math.Tan(9 * Math.PI / 20))
return 1;
else
return 20;
}
else
{
if (y > x * Math.Tan(-3 * Math.PI / 20))
return 10;
if (y > x * Math.Tan(-5 * Math.PI / 20))
return 15;
if (y > x * Math.Tan(-7 * Math.PI / 20))
return 2;
if (y > x * Math.Tan(-9 * Math.PI / 20))
return 17;
else
return 3;
}
}
}
else
{
if (Math.Abs(y) < x * Math.Tan(Math.PI + Math.PI / 20))
return 11;
else
{
if (y > 0)
{
if (y < x * Math.Tan(Math.PI + 3 * Math.PI / 20))
return 14;
if (y < x * Math.Tan(Math.PI + 5 * Math.PI / 20))
return 9;
if (y < x * Math.Tan(Math.PI + 7 * Math.PI / 20))
return 12;
if (y < x * Math.Tan(Math.PI + 9 * Math.PI / 20))
return 5;
else
return 20;
}
else
{
if (y > x * Math.Tan(Math.PI + -3 * Math.PI / 20))
return 8;
if (y > x * Math.Tan(Math.PI + -5 * Math.PI / 20))
return 16;
if (y > x * Math.Tan(Math.PI + -7 * Math.PI / 20))
return 7;
if (y > x * Math.Tan(Math.PI + -9 * Math.PI / 20))
return 19;
else
return 3;
}
}
}
}
}
}

View File

@ -13,80 +13,31 @@ Ambas em milimetros.
if mod > 170: if mod > 170:
print('Fora do alvo.') print('Fora do alvo.')
exit(1) return
if mod < 12.7: if mod < 12.7:
print('Pontuacao: 50 pontos.') print('Pontuacao: 50 pontos.')
exit(1) return
elif mod < 32: elif mod < 32:
print('Pontuacao: 25 pontos.') print('Pontuacao: 25 pontos.')
exit(1) return
base_point = BasePoint(x, y)
score = BasePoint(x, y)
if mod > 99 and mod < 107: if mod > 99 and mod < 107:
print('Pontuacao: {}pontos.'.format(base_point * 3)) score *= 3
exit(1)
if mod > 162: if mod > 162:
print('Pontuacao: {}pontos.'.format(base_point * 2)) score *= 2
exit(1)
print('Pontuacao: {}pontos.'.format(base_point)) print(f'Pontuacao: {score} pontos.')
exit(1) exit(1)
def BasePoint(x, y): def BasePoint(x, y):
if x > 0: angleRad = math.atan2(y, x)
if abs(y) < x * math.tan(math.pi / 20): angleDeg = math.degrees(angleRad) - 9
return 6
else: POINTS = (6, 13, 4, 18, 1, 20, 5, 12, 9, 14, 11, 8, 16, 7, 19, 3, 17, 2, 15, 10)
if y > 0:
if y < x * math.tan(3 * math.pi / 20): return POINTS[int(angleDeg / 20)]
return 13
if y < x * math.tan(5 * math.pi / 20):
return 4
if y < x * math.tan(7 * math.pi / 20):
return 18
if y < x * math.tan(9 * math.pi / 20):
return 1
else:
return 20
else:
if y > x * math.tan(-3 * math.pi / 20):
return 10
if y > x * math.tan(-5 * math.pi / 20):
return 15
if y > x * math.tan(-7 * math.pi / 20):
return 2
if y > x * math.tan(-9 * math.pi / 20):
return 17
else:
return 3
else:
if abs(y) < x * math.tan(math.pi + math.pi / 20):
return 6
else:
if y > 0:
if y < x * math.tan(math.pi + 3 * math.pi / 20):
return 14
if y < x * math.tan(math.pi + 5 * math.pi / 20):
return 9
if y < x * math.tan(math.pi + 7 * math.pi / 20):
return 12
if y < x * math.tan(math.pi + 9 * math.pi / 20):
return 5
else:
return 20
else:
if y > x * math.tan(math.pi + -3 * math.pi / 20):
return 8
if y > x * math.tan(math.pi + -5 * math.pi / 20):
return 16
if y > x * math.tan(math.pi + -7 * math.pi / 20):
return 7
if y > x * math.tan(math.pi + -9 * math.pi / 20):
return 19
else:
return 3
if __name__ == '__main__': if __name__ == '__main__':
main() main()