Removed darts.cs

This commit is contained in:
tiagorg 2022-10-21 16:58:49 +01:00
parent 305664cfc4
commit 6de40e65f5
Signed by untrusted user who does not match committer: TiagoRG
GPG Key ID: DFCD48E3F420DB42
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:
print('Fora do alvo.')
exit(1)
return
if mod < 12.7:
print('Pontuacao: 50 pontos.')
exit(1)
return
elif mod < 32:
print('Pontuacao: 25 pontos.')
exit(1)
base_point = BasePoint(x, y)
return
score = BasePoint(x, y)
if mod > 99 and mod < 107:
print('Pontuacao: {}pontos.'.format(base_point * 3))
exit(1)
score *= 3
if mod > 162:
print('Pontuacao: {}pontos.'.format(base_point * 2))
exit(1)
score *= 2
print('Pontuacao: {}pontos.'.format(base_point))
print(f'Pontuacao: {score} pontos.')
exit(1)
def BasePoint(x, y):
if x > 0:
if 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 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
angleRad = math.atan2(y, x)
angleDeg = math.degrees(angleRad) - 9
POINTS = (6, 13, 4, 18, 1, 20, 5, 12, 9, 14, 11, 8, 16, 7, 19, 3, 17, 2, 15, 10)
return POINTS[int(angleDeg / 20)]
if __name__ == '__main__':
main()