Spaces:
Sleeping
Sleeping
Commit
·
9855827
1
Parent(s):
e0eeafb
a1
Browse files- README.md +44 -7
- app.py +665 -0
- requirements.txt +1 -0
README.md
CHANGED
@@ -1,13 +1,50 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
license: ecl-2.0
|
11 |
---
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
title: sentiment-analysis-committee
|
3 |
+
emoji: 👥
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: green
|
6 |
sdk: gradio
|
7 |
+
sdk_version: "4.12.0"
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
|
12 |
+
|
13 |
+
# Sentiment Analysis Committee
|
14 |
+
|
15 |
+
A comprehensive sentiment analysis tool using multiple methods, including BERT (Base and Large), DistilBERT, SiEBERT, TextBlob, VADER, and AFINN.
|
16 |
+
|
17 |
+
## How to Use
|
18 |
+
|
19 |
+
Enter text into the interface to receive sentiment analyses from various methods. The committee's decision is based on the majority of votes among the methods.
|
20 |
+
|
21 |
+
## Technical Details
|
22 |
+
|
23 |
+
This project leverages various natural language processing models to evaluate the sentiment of entered text:
|
24 |
+
|
25 |
+
- **BERT Base and BERT Large**: Transformer-based models providing sentiment scores and labels. BERT Large is a larger variant of BERT with more layers, potentially offering more nuanced sentiment analysis.
|
26 |
+
- **DistilBERT**: A distilled version of BERT, optimized for speed and efficiency.
|
27 |
+
- **SiEBERT**: A RoBERTa-based model fine-tuned for sentiment analysis.
|
28 |
+
- **TextBlob**: Utilizes Naive Bayes classifiers, offering straightforward sentiment evaluations.
|
29 |
+
- **VADER**: Designed for social media and short texts, giving a compound sentiment score.
|
30 |
+
- **AFINN**: A lexical method assigning scores to words, indicating sentiment intensity.
|
31 |
+
|
32 |
+
The final decision of the committee is determined by a majority vote approach, providing a balanced sentiment analysis.
|
33 |
+
|
34 |
+
## Additional Information
|
35 |
+
|
36 |
+
- Developed by Ramon Mayor Martins (2023)
|
37 |
+
- E-mail: [[email protected]](mailto:[email protected])
|
38 |
+
- Homepage: [https://rmayormartins.github.io/](https://rmayormartins.github.io/)
|
39 |
+
- Twitter: [@rmayormartins](https://twitter.com/rmayormartins)
|
40 |
+
- GitHub: [https://github.com/rmayormartins](https://github.com/rmayormartins)
|
41 |
+
|
42 |
+
## Notes
|
43 |
+
|
44 |
+
- The committee's decision is democratic, based on the majority vote from the utilized methods.
|
45 |
+
- The project is implemented in Python and hosted on Hugging Face Spaces.
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
+
|
app.py
ADDED
@@ -0,0 +1,665 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import subprocess
|
4 |
+
import time
|
5 |
+
from collections import deque
|
6 |
+
|
7 |
+
# Criar pasta para armazenar as classes Java
|
8 |
+
os.makedirs("combat_classes", exist_ok=True)
|
9 |
+
|
10 |
+
# Templates de código para as aeronaves com altura dinâmica e novos atributos
|
11 |
+
TEAM1_TEMPLATE = '''import java.util.ArrayList;
|
12 |
+
import java.util.Random;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Time 1 - Configure sua aeronave!
|
16 |
+
*
|
17 |
+
* SISTEMA DE PONTOS:
|
18 |
+
* - Você tem 100 pontos para distribuir entre os atributos
|
19 |
+
* - Escolha com sabedoria para criar uma aeronave competitiva
|
20 |
+
*
|
21 |
+
* ATRIBUTOS:
|
22 |
+
* - speed: Velocidade da aeronave (1-10) - Afeta quão rápido sua aeronave pode se mover
|
23 |
+
* - fireRate: Taxa de disparo (1-10) - Controla com que frequência sua aeronave pode atirar
|
24 |
+
* - maneuverability: Manobrabilidade (1-10) - Facilita mudanças de altitude e esquivas
|
25 |
+
* - shotPower: Poder do tiro normal (5-20) - Dano causado por tiros normais
|
26 |
+
* - supersonicPower: Poder do tiro supersônico (10-30) - Dano causado por tiros supersônicos
|
27 |
+
* - missilePower: Poder do míssil (15-40) - Dano causado pelo míssil especial
|
28 |
+
* - defense: Defesa (5-25) - Reduz o dano recebido
|
29 |
+
* - stealthChance: Chance de furtividade (0-20) - Probabilidade de evitar ataques
|
30 |
+
* - radar: Radar (0-10) - Capacidade de detectar projéteis inimigos
|
31 |
+
* - doubleShot: Tiro duplo (0-10) - Permite disparar em duas altitudes diferentes
|
32 |
+
* - nuclearPower: Poder nuclear (0-10) - Poder do míssil nuclear (dano massivo)
|
33 |
+
*/
|
34 |
+
public class Team1Aircraft extends Aircraft {
|
35 |
+
private Random random = new Random();
|
36 |
+
private int maxAltitude; // Armazena a altura máxima do campo
|
37 |
+
|
38 |
+
public Team1Aircraft() {
|
39 |
+
super(
|
40 |
+
// DISTRIBUA 100 PONTOS ENTRE ESSES ATRIBUTOS
|
41 |
+
5, // Velocidade (1-10)
|
42 |
+
5, // Taxa de fogo (1-10)
|
43 |
+
5, // Manobrabilidade (1-10)
|
44 |
+
15, // Dano do tiro normal (5-20)
|
45 |
+
20, // Dano do tiro supersônico (10-30)
|
46 |
+
25, // Dano do míssil (15-40)
|
47 |
+
15, // Defesa (5-25)
|
48 |
+
5, // Chance de furtividade (0-20)
|
49 |
+
2, // Radar (0-10)
|
50 |
+
2, // Tiro duplo (0-10)
|
51 |
+
1, // Poder nuclear (0-10)
|
52 |
+
"▶" // Símbolo da aeronave (não altere)
|
53 |
+
);
|
54 |
+
|
55 |
+
// IMPORTANTE: A soma de todos os atributos deve ser <= 100
|
56 |
+
// Exemplo: 5+5+5+15+20+25+15+5+2+2+1 = 100
|
57 |
+
|
58 |
+
// Verifica dinamicamente a altura do campo (será definida pelo BattleMain)
|
59 |
+
try {
|
60 |
+
String heightEnv = System.getProperty("battlefield.height", "3");
|
61 |
+
maxAltitude = Integer.parseInt(heightEnv) - 1;
|
62 |
+
} catch (Exception e) {
|
63 |
+
maxAltitude = 2; // Valor padrão se não conseguir ler
|
64 |
+
}
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Controla o movimento da aeronave.
|
69 |
+
* Valor padrão: Movimento aleatório baseado na velocidade
|
70 |
+
* Dica: Você pode personalizar para criar padrões de movimento mais inteligentes
|
71 |
+
*/
|
72 |
+
@Override
|
73 |
+
public int move() {
|
74 |
+
// Retorna um número entre -speed/2 e +speed
|
75 |
+
return random.nextInt(speed + 1) - speed / 2;
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Controla a mudança de altitude da aeronave.
|
80 |
+
* Valor padrão: Mudança aleatória entre subir, descer ou manter altitude
|
81 |
+
* Dica: Uma boa estratégia pode aumentar suas chances de esquiva
|
82 |
+
*/
|
83 |
+
@Override
|
84 |
+
public int changeAltitude() {
|
85 |
+
int direction = random.nextInt(3) - 1; // -1 (descer), 0 (manter), 1 (subir)
|
86 |
+
this.posY = Math.max(0, Math.min(maxAltitude, posY + direction));
|
87 |
+
return direction;
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Tiro normal - mais frequente, menos dano
|
92 |
+
*/
|
93 |
+
@Override
|
94 |
+
public Projectile shoot(int posX, int direction) {
|
95 |
+
return new Projectile(posX, this.posY, direction, 1, "->");
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Tiro supersônico - mais rápido, mais dano
|
100 |
+
*/
|
101 |
+
@Override
|
102 |
+
public Projectile shootSupersonic(int posX, int direction) {
|
103 |
+
return new Projectile(posX, this.posY, direction, 2, ">>");
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Míssil especial - muito dano, com cooldown
|
108 |
+
*/
|
109 |
+
@Override
|
110 |
+
public Projectile specialMissile(int posX, int direction) {
|
111 |
+
if (missileCooldown == 0) {
|
112 |
+
missileCooldown = 3; // Espera 3 turnos para usar novamente
|
113 |
+
return new Projectile(posX, this.posY, direction, 1, "=>");
|
114 |
+
}
|
115 |
+
missileCooldown--;
|
116 |
+
return null;
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Tiro duplo - ataca em duas altitudes diferentes
|
121 |
+
*/
|
122 |
+
@Override
|
123 |
+
public Projectile doubleShot(int posX, int direction) {
|
124 |
+
// Define a segunda altitude para o tiro (diferente da atual)
|
125 |
+
int currentAlt = this.posY;
|
126 |
+
int secondAlt = (currentAlt + 1) % (maxAltitude + 1);
|
127 |
+
|
128 |
+
// Guarda essa altitude para ser usada pelo BattleMain
|
129 |
+
this.secondShotAltitude = secondAlt;
|
130 |
+
|
131 |
+
// Retorna o projétil principal
|
132 |
+
return new Projectile(posX, this.posY, direction, 1, "⇉");
|
133 |
+
}
|
134 |
+
|
135 |
+
/**
|
136 |
+
* Míssil nuclear - dano massivo
|
137 |
+
*/
|
138 |
+
@Override
|
139 |
+
public Projectile nuclearMissile(int posX, int direction) {
|
140 |
+
if (missileCooldown == 0) {
|
141 |
+
missileCooldown = 5; // Longo cooldown para o poder nuclear
|
142 |
+
return new Projectile(posX, this.posY, direction, 1, "-]=>");
|
143 |
+
}
|
144 |
+
return null;
|
145 |
+
}
|
146 |
+
|
147 |
+
/**
|
148 |
+
* Radar - detecta projéteis inimigos
|
149 |
+
*/
|
150 |
+
@Override
|
151 |
+
public void radarScan(ArrayList<Projectile> projectiles, int enemyPosX, int enemyPosY) {
|
152 |
+
// Implementação básica: apenas detecta projéteis próximos
|
153 |
+
// Em uma implementação mais avançada, você poderia usar essas informações
|
154 |
+
// para ajustar seu movimento e evitar projéteis
|
155 |
+
}
|
156 |
+
}'''
|
157 |
+
|
158 |
+
TEAM2_TEMPLATE = '''import java.util.ArrayList;
|
159 |
+
import java.util.Random;
|
160 |
+
|
161 |
+
/**
|
162 |
+
* Time 2 - Configure sua aeronave!
|
163 |
+
*
|
164 |
+
* SISTEMA DE PONTOS:
|
165 |
+
* - Você tem 100 pontos para distribuir entre os atributos
|
166 |
+
* - Escolha com sabedoria para criar uma aeronave competitiva
|
167 |
+
*
|
168 |
+
* ATRIBUTOS:
|
169 |
+
* - speed: Velocidade da aeronave (1-10) - Afeta quão rápido sua aeronave pode se mover
|
170 |
+
* - fireRate: Taxa de disparo (1-10) - Controla com que frequência sua aeronave pode atirar
|
171 |
+
* - maneuverability: Manobrabilidade (1-10) - Facilita mudanças de altitude e esquivas
|
172 |
+
* - shotPower: Poder do tiro normal (5-20) - Dano causado por tiros normais
|
173 |
+
* - supersonicPower: Poder do tiro supersônico (10-30) - Dano causado por tiros supersônicos
|
174 |
+
* - missilePower: Poder do míssil (15-40) - Dano causado pelo míssil especial
|
175 |
+
* - defense: Defesa (5-25) - Reduz o dano recebido
|
176 |
+
* - stealthChance: Chance de furtividade (0-20) - Probabilidade de evitar ataques
|
177 |
+
* - radar: Radar (0-10) - Capacidade de detectar projéteis inimigos
|
178 |
+
* - doubleShot: Tiro duplo (0-10) - Permite disparar em duas altitudes diferentes
|
179 |
+
* - nuclearPower: Poder nuclear (0-10) - Poder do míssil nuclear (dano massivo)
|
180 |
+
*/
|
181 |
+
public class Team2Aircraft extends Aircraft {
|
182 |
+
private Random random = new Random();
|
183 |
+
private int maxAltitude; // Armazena a altura máxima do campo
|
184 |
+
|
185 |
+
public Team2Aircraft() {
|
186 |
+
super(
|
187 |
+
// DISTRIBUA 100 PONTOS ENTRE ESSES ATRIBUTOS
|
188 |
+
5, // Velocidade (1-10)
|
189 |
+
5, // Taxa de fogo (1-10)
|
190 |
+
5, // Manobrabilidade (1-10)
|
191 |
+
15, // Dano do tiro normal (5-20)
|
192 |
+
20, // Dano do tiro supersônico (10-30)
|
193 |
+
25, // Dano do míssil (15-40)
|
194 |
+
15, // Defesa (5-25)
|
195 |
+
5, // Chance de furtividade (0-20)
|
196 |
+
2, // Radar (0-10)
|
197 |
+
2, // Tiro duplo (0-10)
|
198 |
+
1, // Poder nuclear (0-10)
|
199 |
+
"◀" // Símbolo da aeronave (não altere)
|
200 |
+
);
|
201 |
+
|
202 |
+
// IMPORTANTE: A soma de todos os atributos deve ser <= 100
|
203 |
+
// Exemplo: 5+5+5+15+20+25+15+5+2+2+1 = 100
|
204 |
+
|
205 |
+
// Verifica dinamicamente a altura do campo (será definida pelo BattleMain)
|
206 |
+
try {
|
207 |
+
String heightEnv = System.getProperty("battlefield.height", "3");
|
208 |
+
maxAltitude = Integer.parseInt(heightEnv) - 1;
|
209 |
+
} catch (Exception e) {
|
210 |
+
maxAltitude = 2; // Valor padrão se não conseguir ler
|
211 |
+
}
|
212 |
+
}
|
213 |
+
|
214 |
+
/**
|
215 |
+
* Controla o movimento da aeronave.
|
216 |
+
* Valor padrão: Movimento aleatório baseado na velocidade
|
217 |
+
* Dica: Você pode personalizar para criar padrões de movimento mais inteligentes
|
218 |
+
*/
|
219 |
+
@Override
|
220 |
+
public int move() {
|
221 |
+
// Retorna um número entre -speed/2 e +speed
|
222 |
+
return random.nextInt(speed + 1) - speed / 2;
|
223 |
+
}
|
224 |
+
|
225 |
+
/**
|
226 |
+
* Controla a mudança de altitude da aeronave.
|
227 |
+
* Valor padrão: Mudança aleatória entre subir, descer ou manter altitude
|
228 |
+
* Dica: Uma boa estratégia pode aumentar suas chances de esquiva
|
229 |
+
*/
|
230 |
+
@Override
|
231 |
+
public int changeAltitude() {
|
232 |
+
int direction = random.nextInt(3) - 1; // -1 (descer), 0 (manter), 1 (subir)
|
233 |
+
this.posY = Math.max(0, Math.min(maxAltitude, posY + direction));
|
234 |
+
return direction;
|
235 |
+
}
|
236 |
+
|
237 |
+
/**
|
238 |
+
* Tiro normal - mais frequente, menos dano
|
239 |
+
*/
|
240 |
+
@Override
|
241 |
+
public Projectile shoot(int posX, int direction) {
|
242 |
+
return new Projectile(posX, this.posY, direction, 1, "<-");
|
243 |
+
}
|
244 |
+
|
245 |
+
/**
|
246 |
+
* Tiro supersônico - mais rápido, mais dano
|
247 |
+
*/
|
248 |
+
@Override
|
249 |
+
public Projectile shootSupersonic(int posX, int direction) {
|
250 |
+
return new Projectile(posX, this.posY, direction, 2, "<<");
|
251 |
+
}
|
252 |
+
|
253 |
+
/**
|
254 |
+
* Míssil especial - muito dano, com cooldown
|
255 |
+
*/
|
256 |
+
@Override
|
257 |
+
public Projectile specialMissile(int posX, int direction) {
|
258 |
+
if (missileCooldown == 0) {
|
259 |
+
missileCooldown = 3; // Espera 3 turnos para usar novamente
|
260 |
+
return new Projectile(posX, this.posY, direction, 1, "<=");
|
261 |
+
}
|
262 |
+
missileCooldown--;
|
263 |
+
return null;
|
264 |
+
}
|
265 |
+
|
266 |
+
/**
|
267 |
+
* Tiro duplo - ataca em duas altitudes diferentes
|
268 |
+
*/
|
269 |
+
@Override
|
270 |
+
public Projectile doubleShot(int posX, int direction) {
|
271 |
+
// Define a segunda altitude para o tiro (diferente da atual)
|
272 |
+
int currentAlt = this.posY;
|
273 |
+
int secondAlt = (currentAlt + 1) % (maxAltitude + 1);
|
274 |
+
|
275 |
+
// Guarda essa altitude para ser usada pelo BattleMain
|
276 |
+
this.secondShotAltitude = secondAlt;
|
277 |
+
|
278 |
+
// Retorna o projétil principal
|
279 |
+
return new Projectile(posX, this.posY, direction, 1, "⇇");
|
280 |
+
}
|
281 |
+
|
282 |
+
/**
|
283 |
+
* Míssil nuclear - dano massivo
|
284 |
+
*/
|
285 |
+
@Override
|
286 |
+
public Projectile nuclearMissile(int posX, int direction) {
|
287 |
+
if (missileCooldown == 0) {
|
288 |
+
missileCooldown = 5; // Longo cooldown para o poder nuclear
|
289 |
+
return new Projectile(posX, this.posY, direction, 1, "<[=-");
|
290 |
+
}
|
291 |
+
return null;
|
292 |
+
}
|
293 |
+
|
294 |
+
/**
|
295 |
+
* Radar - detecta projéteis inimigos
|
296 |
+
*/
|
297 |
+
@Override
|
298 |
+
public void radarScan(ArrayList<Projectile> projectiles, int enemyPosX, int enemyPosY) {
|
299 |
+
// Implementação básica: apenas detecta projéteis próximos
|
300 |
+
// Em uma implementação mais avançada, você poderia usar essas informações
|
301 |
+
// para ajustar seu movimento e evitar projéteis
|
302 |
+
}
|
303 |
+
}'''
|
304 |
+
|
305 |
+
# Código base das classes Aircraft e Projectile
|
306 |
+
aircraft_code = """
|
307 |
+
import java.util.ArrayList;
|
308 |
+
|
309 |
+
public abstract class Aircraft {
|
310 |
+
protected int health; // Agora definido externamente
|
311 |
+
protected int speed;
|
312 |
+
protected int fireRate;
|
313 |
+
protected int maneuverability;
|
314 |
+
protected int shotPower;
|
315 |
+
protected int supersonicPower;
|
316 |
+
protected int missilePower;
|
317 |
+
protected int defense;
|
318 |
+
protected int stealthChance;
|
319 |
+
protected int radar;
|
320 |
+
protected int doubleShot;
|
321 |
+
protected int doubleShotPower;
|
322 |
+
protected int nuclearPower;
|
323 |
+
protected int secondShotAltitude = -1;
|
324 |
+
protected int missileCooldown = 0;
|
325 |
+
protected int posY = 1;
|
326 |
+
protected String symbol;
|
327 |
+
protected static final int TOTAL_POINTS = 100;
|
328 |
+
|
329 |
+
public Aircraft(int speed, int fireRate, int maneuverability, int shotPower, int supersonicPower,
|
330 |
+
int missilePower, int defense, int stealthChance, int radar, int doubleShot,
|
331 |
+
int nuclearPower, String symbol) {
|
332 |
+
this.health = 100; // Valor padrão que será substituído
|
333 |
+
this.speed = speed;
|
334 |
+
this.fireRate = fireRate;
|
335 |
+
this.maneuverability = maneuverability;
|
336 |
+
this.shotPower = shotPower;
|
337 |
+
this.supersonicPower = supersonicPower;
|
338 |
+
this.missilePower = missilePower;
|
339 |
+
this.defense = defense;
|
340 |
+
this.stealthChance = stealthChance;
|
341 |
+
this.radar = radar;
|
342 |
+
this.doubleShot = doubleShot;
|
343 |
+
this.doubleShotPower = doubleShot;
|
344 |
+
this.nuclearPower = nuclearPower;
|
345 |
+
this.symbol = symbol;
|
346 |
+
|
347 |
+
validateAttributes();
|
348 |
+
}
|
349 |
+
|
350 |
+
public void setInitialHealth(int health) {
|
351 |
+
this.health = health;
|
352 |
+
}
|
353 |
+
|
354 |
+
private void validateAttributes() {
|
355 |
+
int total = speed + fireRate + maneuverability + shotPower + supersonicPower +
|
356 |
+
missilePower + defense + stealthChance + radar + doubleShot + nuclearPower;
|
357 |
+
if (total > TOTAL_POINTS) {
|
358 |
+
throw new IllegalArgumentException("Erro: A soma dos atributos excede " + TOTAL_POINTS + " pontos! Total: " + total);
|
359 |
+
}
|
360 |
+
}
|
361 |
+
|
362 |
+
public abstract int move();
|
363 |
+
public abstract int changeAltitude();
|
364 |
+
public abstract Projectile shoot(int posX, int direction);
|
365 |
+
public abstract Projectile shootSupersonic(int posX, int direction);
|
366 |
+
public abstract Projectile specialMissile(int posX, int direction);
|
367 |
+
public abstract Projectile doubleShot(int posX, int direction);
|
368 |
+
public abstract Projectile nuclearMissile(int posX, int direction);
|
369 |
+
public abstract void radarScan(ArrayList<Projectile> projectiles, int enemyPosX, int enemyPosY);
|
370 |
+
|
371 |
+
public int getHealth() {
|
372 |
+
return health;
|
373 |
+
}
|
374 |
+
|
375 |
+
public void takeDamage(int damage) {
|
376 |
+
this.health -= Math.max(0, damage - (defense / 10));
|
377 |
+
}
|
378 |
+
|
379 |
+
public boolean isAlive() {
|
380 |
+
return health > 0;
|
381 |
+
}
|
382 |
+
|
383 |
+
public int getPositionY() {
|
384 |
+
return posY;
|
385 |
+
}
|
386 |
+
|
387 |
+
public int getSecondShotAltitude() {
|
388 |
+
int alt = secondShotAltitude;
|
389 |
+
secondShotAltitude = -1; // Reset após uso
|
390 |
+
return alt;
|
391 |
+
}
|
392 |
+
}
|
393 |
+
"""
|
394 |
+
|
395 |
+
projectile_code = """
|
396 |
+
public class Projectile {
|
397 |
+
int posX;
|
398 |
+
int posY;
|
399 |
+
int direction;
|
400 |
+
int speed;
|
401 |
+
String symbol;
|
402 |
+
int power = 0; // Poder do projétil, usado para dano personalizado
|
403 |
+
|
404 |
+
public Projectile(int posX, int posY, int direction, int speed, String symbol) {
|
405 |
+
this.posX = posX;
|
406 |
+
this.posY = posY;
|
407 |
+
this.direction = direction;
|
408 |
+
this.speed = speed;
|
409 |
+
this.symbol = symbol;
|
410 |
+
}
|
411 |
+
|
412 |
+
public Projectile(int posX, int posY, int direction, int speed, String symbol, int power) {
|
413 |
+
this(posX, posY, direction, speed, symbol);
|
414 |
+
this.power = power;
|
415 |
+
}
|
416 |
+
|
417 |
+
public void move() {
|
418 |
+
posX += direction * speed;
|
419 |
+
}
|
420 |
+
|
421 |
+
public boolean isOutOfBounds(int screenWidth) {
|
422 |
+
return (posX < 0 || posX >= screenWidth);
|
423 |
+
}
|
424 |
+
|
425 |
+
public int getPower() {
|
426 |
+
return power;
|
427 |
+
}
|
428 |
+
}
|
429 |
+
"""
|
430 |
+
|
431 |
+
def run_battle(code1, code2, screen_width, battlefield_height, p1_start_pos, p2_start_pos, team1_health, team2_health):
|
432 |
+
# Caminhos dos arquivos Java
|
433 |
+
aircraft_path = "combat_classes/Aircraft.java"
|
434 |
+
projectile_path = "combat_classes/Projectile.java"
|
435 |
+
class1_path = "combat_classes/Team1Aircraft.java"
|
436 |
+
class2_path = "combat_classes/Team2Aircraft.java"
|
437 |
+
main_path = "combat_classes/BattleMain.java"
|
438 |
+
|
439 |
+
# Gerar o código do BattleMain com os parâmetros configuráveis
|
440 |
+
battle_main_code = f"""
|
441 |
+
import java.util.ArrayList;
|
442 |
+
import java.util.Iterator;
|
443 |
+
import java.util.Random;
|
444 |
+
|
445 |
+
public class BattleMain {{
|
446 |
+
public static void main(String[] args) {{
|
447 |
+
// Definir a altura do campo como propriedade do sistema
|
448 |
+
System.setProperty("battlefield.height", "{battlefield_height}");
|
449 |
+
|
450 |
+
Aircraft team1 = new Team1Aircraft();
|
451 |
+
Aircraft team2 = new Team2Aircraft();
|
452 |
+
|
453 |
+
// Definir a vida inicial de cada aeronave
|
454 |
+
team1.setInitialHealth({team1_health});
|
455 |
+
team2.setInitialHealth({team2_health});
|
456 |
+
|
457 |
+
Random random = new Random();
|
458 |
+
|
459 |
+
int p1PosX = {p1_start_pos};
|
460 |
+
int p2PosX = {p2_start_pos};
|
461 |
+
int screenWidth = {screen_width};
|
462 |
+
int battlefieldHeight = {battlefield_height};
|
463 |
+
ArrayList<Projectile> projectiles = new ArrayList<>();
|
464 |
+
|
465 |
+
// Inicializar as altitudes das naves em uma posição média do campo
|
466 |
+
team1.posY = battlefieldHeight / 2;
|
467 |
+
team2.posY = battlefieldHeight / 2;
|
468 |
+
|
469 |
+
while (team1.isAlive() && team2.isAlive()) {{
|
470 |
+
System.out.println("\\n=== NOVO TURNO ===");
|
471 |
+
System.out.flush();
|
472 |
+
|
473 |
+
String[][] battlefield = new String[battlefieldHeight][screenWidth];
|
474 |
+
for (int row = 0; row < battlefieldHeight; row++) {{
|
475 |
+
for (int i = 0; i < screenWidth; i++) {{
|
476 |
+
battlefield[row][i] = " ";
|
477 |
+
}}
|
478 |
+
}}
|
479 |
+
|
480 |
+
// Radar scan para detectar projéteis
|
481 |
+
team1.radarScan(projectiles, p2PosX, team2.getPositionY());
|
482 |
+
team2.radarScan(projectiles, p1PosX, team1.getPositionY());
|
483 |
+
|
484 |
+
// Movimento das aeronaves
|
485 |
+
p1PosX += team1.move();
|
486 |
+
p2PosX += team2.move();
|
487 |
+
p1PosX = Math.max(0, Math.min(screenWidth - 1, p1PosX));
|
488 |
+
p2PosX = Math.max(0, Math.min(screenWidth - 1, p2PosX));
|
489 |
+
|
490 |
+
// Mudança de altitude
|
491 |
+
team1.changeAltitude();
|
492 |
+
team2.changeAltitude();
|
493 |
+
// Garantir que a altitude não exceda o novo tamanho do campo de batalha
|
494 |
+
team1.posY = Math.min(team1.posY, battlefieldHeight - 1);
|
495 |
+
team2.posY = Math.min(team2.posY, battlefieldHeight - 1);
|
496 |
+
|
497 |
+
// Atirar para Time 1
|
498 |
+
if (random.nextInt(10) < team1.fireRate) {{
|
499 |
+
Projectile shot = null;
|
500 |
+
int shotType = random.nextInt(100);
|
501 |
+
|
502 |
+
// Escolha aleatória do tipo de tiro baseado na probabilidade
|
503 |
+
if (shotType < 5 && team1.nuclearPower > 0) {{
|
504 |
+
// Tiro nuclear (baixa probabilidade)
|
505 |
+
shot = team1.nuclearMissile(p1PosX, 1);
|
506 |
+
if (shot != null) {{
|
507 |
+
System.out.println("☢️ Time 1 lançou um MÍSSIL NUCLEAR!");
|
508 |
+
}}
|
509 |
+
}} else if (shotType < 15 && team1.doubleShot > 0) {{
|
510 |
+
// Tiro duplo
|
511 |
+
shot = team1.doubleShot(p1PosX, 1);
|
512 |
+
if (shot != null) {{
|
513 |
+
System.out.println("➡️ Time 1 disparou um TIRO DUPLO!");
|
514 |
+
// Adicionar o segundo projétil em uma altitude diferente
|
515 |
+
int secAlt = team1.getSecondShotAltitude();
|
516 |
+
if (secAlt >= 0 && secAlt < battlefieldHeight) {{
|
517 |
+
projectiles.add(new Projectile(p1PosX, secAlt, 1, 1, "->", team1.doubleShotPower));
|
518 |
+
}}
|
519 |
+
}}
|
520 |
+
}} else if (shotType < 30) {{
|
521 |
+
// Míssil especial
|
522 |
+
shot = team1.specialMissile(p1PosX, 1);
|
523 |
+
}} else if (shotType < 60) {{
|
524 |
+
// Tiro supersônico
|
525 |
+
shot = team1.shootSupersonic(p1PosX, 1);
|
526 |
+
}} else {{
|
527 |
+
// Tiro normal
|
528 |
+
shot = team1.shoot(p1PosX, 1);
|
529 |
+
}}
|
530 |
+
|
531 |
+
if (shot != null) {{
|
532 |
+
// Garantir que a altitude do projétil não exceda o campo de batalha
|
533 |
+
shot.posY = Math.min(shot.posY, battlefieldHeight - 1);
|
534 |
+
projectiles.add(shot);
|
535 |
+
}}
|
536 |
+
}}
|
537 |
+
|
538 |
+
// Atirar para Time 2
|
539 |
+
if (random.nextInt(10) < team2.fireRate) {{
|
540 |
+
Projectile shot = null;
|
541 |
+
int shotType = random.nextInt(100);
|
542 |
+
|
543 |
+
// Escolha aleatória do tipo de tiro baseado na probabilidade
|
544 |
+
if (shotType < 5 && team2.nuclearPower > 0) {{
|
545 |
+
// Tiro nuclear (baixa probabilidade)
|
546 |
+
shot = team2.nuclearMissile(p2PosX, -1);
|
547 |
+
if (shot != null) {{
|
548 |
+
System.out.println("☢️ Time 2 lançou um MÍSSIL NUCLEAR!");
|
549 |
+
}}
|
550 |
+
}} else if (shotType < 15 && team2.doubleShot > 0) {{
|
551 |
+
// Tiro duplo
|
552 |
+
shot = team2.doubleShot(p2PosX, -1);
|
553 |
+
if (shot != null) {{
|
554 |
+
System.out.println("⬅️ Time 2 disparou um TIRO DUPLO!");
|
555 |
+
// Adicionar o segundo projétil em uma altitude diferente
|
556 |
+
int secAlt = team2.getSecondShotAltitude();
|
557 |
+
if (secAlt >= 0 && secAlt < battlefieldHeight) {{
|
558 |
+
projectiles.add(new Projectile(p2PosX, secAlt, -1, 1, "<-", team2.doubleShotPower));
|
559 |
+
}}
|
560 |
+
}}
|
561 |
+
}} else if (shotType < 30) {{
|
562 |
+
// Míssil especial
|
563 |
+
shot = team2.specialMissile(p2PosX, -1);
|
564 |
+
}} else if (shotType < 60) {{
|
565 |
+
// Tiro supersônico
|
566 |
+
shot = team2.shootSupersonic(p2PosX, -1);
|
567 |
+
}} else {{
|
568 |
+
// Tiro normal
|
569 |
+
shot = team2.shoot(p2PosX, -1);
|
570 |
+
}}
|
571 |
+
|
572 |
+
if (shot != null) {{
|
573 |
+
// Garantir que a altitude do projétil não exceda o campo de batalha
|
574 |
+
shot.posY = Math.min(shot.posY, battlefieldHeight - 1);
|
575 |
+
projectiles.add(shot);
|
576 |
+
}}
|
577 |
+
}}
|
578 |
+
|
579 |
+
// Posicionar aeronaves no campo de batalha com cores
|
580 |
+
battlefield[team1.getPositionY()][p1PosX] = "\u001B[34m" + team1.symbol + "\u001B[0m"; // Azul para Time 1
|
581 |
+
battlefield[team2.getPositionY()][p2PosX] = "\u001B[31m" + team2.symbol + "\u001B[0m"; // Vermelho para Time 2
|
582 |
+
|
583 |
+
// Mover projéteis e verificar colisões
|
584 |
+
Iterator<Projectile> iterator = projectiles.iterator();
|
585 |
+
while (iterator.hasNext()) {{
|
586 |
+
Projectile p = iterator.next();
|
587 |
+
p.move();
|
588 |
+
|
589 |
+
// Verificar colisões com Time 1
|
590 |
+
if (p.posX == p1PosX && p.posY == team1.getPositionY()) {{
|
591 |
+
int damage = 0;
|
592 |
+
|
593 |
+
// Verificar se o projétil tem poder personalizado
|
594 |
+
if (p.getPower() > 0) {{
|
595 |
+
damage = p.getPower();
|
596 |
+
}} else if (p.symbol.contains("<[=-")) {{ // Míssil nuclear do Time 2
|
597 |
+
damage = team2.nuclearPower * 2;
|
598 |
+
System.out.println("💥💥💥 MÍSSIL NUCLEAR do Time 2 atingiu o Time 1!");
|
599 |
+
}} else if (p.symbol.contains("⇇")) {{ // Tiro duplo do Time 2
|
600 |
+
damage = team2.doubleShotPower;
|
601 |
+
}} else if (p.symbol.equals("<=")) {{
|
602 |
+
damage = team2.missilePower;
|
603 |
+
}} else if (p.symbol.equals("<<")) {{
|
604 |
+
damage = team2.supersonicPower;
|
605 |
+
}} else {{
|
606 |
+
damage = team2.shotPower;
|
607 |
+
}}
|
608 |
+
|
609 |
+
if (random.nextInt(100) >= team1.stealthChance) {{
|
610 |
+
team1.takeDamage(damage);
|
611 |
+
System.out.println("💥 Aeronave do Time 1 atingida! -" + damage + " pontos");
|
612 |
+
}} else {{
|
613 |
+
System.out.println("👻 Aeronave do Time 1 esquivou!");
|
614 |
+
if (team1.radar > 0) {{
|
615 |
+
System.out.println("📡 Radar do Time 1 detectou o projétil!");
|
616 |
+
}}
|
617 |
+
}}
|
618 |
+
iterator.remove();
|
619 |
+
continue;
|
620 |
+
}}
|
621 |
+
|
622 |
+
// Verificar colisões com Time 2
|
623 |
+
if (p.posX == p2PosX && p.posY == team2.getPositionY()) {{
|
624 |
+
int damage = 0;
|
625 |
+
|
626 |
+
// Verificar se o projétil tem poder personalizado
|
627 |
+
if (p.getPower() > 0) {{
|
628 |
+
damage = p.getPower();
|
629 |
+
}} else if (p.symbol.contains("-]=>")) {{ // Míssil nuclear do Time 1
|
630 |
+
damage = team1.nuclearPower * 2;
|
631 |
+
System.out.println("💥💥💥 MÍSSIL NUCLEAR do Time 1 atingiu o Time 2!");
|
632 |
+
}} else if (p.symbol.contains("⇉")) {{ // Tiro duplo do Time 1
|
633 |
+
damage = team1.doubleShotPower;
|
634 |
+
}} else if (p.symbol.equals("=>")) {{
|
635 |
+
damage = team1.missilePower;
|
636 |
+
}} else if (p.symbol.equals(">>")) {{
|
637 |
+
damage = team1.supersonicPower;
|
638 |
+
}} else {{
|
639 |
+
damage = team1.shotPower;
|
640 |
+
}}
|
641 |
+
|
642 |
+
if (random.nextInt(100) >= team2.stealthChance) {{
|
643 |
+
team2.takeDamage(damage);
|
644 |
+
System.out.println("💥 Aeronave do Time 2 atingida! -" + damage + " pontos");
|
645 |
+
}} else {{
|
646 |
+
System.out.println("👻 Aeronave do Time 2 esquivou!");
|
647 |
+
if (team2.radar > 0) {{
|
648 |
+
System.out.println("📡 Radar do Time 2 detectou o projétil!");
|
649 |
+
}}
|
650 |
+
}}
|
651 |
+
iterator.remove();
|
652 |
+
continue;
|
653 |
+
}}
|
654 |
+
|
655 |
+
// Remover projéteis fora dos limites
|
656 |
+
if (p.isOutOfBounds(screenWidth)) {{
|
657 |
+
iterator.remove();
|
658 |
+
continue;
|
659 |
+
}}
|
660 |
+
|
661 |
+
// Mostrar projéteis no campo de batalha com cores
|
662 |
+
if (p.posX >= 0 && p.posX < screenWidth && p.posY >= 0 && p.posY < battlefieldHeight) {{
|
663 |
+
// Adicionar cores aos projéteis baseado na direção
|
664 |
+
if (p.direction > 0) {{
|
665 |
+
battlefield[p.posY][p.posX]
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
gradio==4.44.0
|