fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Collections;
  11. using System.IO;
  12.  
  13. namespace WindowsFormsApplication2
  14. {
  15. public partial class Form1 : Form
  16. {
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. }
  21. ArrayList teamList = new ArrayList();
  22. ArrayList playerList = new ArrayList();
  23. ateam myteam = new ateam();
  24. scoreboard myscore = new scoreboard();
  25. scoreboard imprvscore = new scoreboard();
  26. float gameplayed;
  27. float gameleft;
  28. int orankDiff;
  29. float FGM, FGA, FTM, FTA;
  30.  
  31. private void Form1_Load(object sender, EventArgs e)
  32. {
  33. // TODO: 這行程式碼會將資料載入 'nBA_DataSet.Players' 資料表。您可以視需要進行移動或移除。
  34. this.playersTableAdapter.Fill(this.nBA_DataSet.Players);
  35. // TODO: 這行程式碼會將資料載入 'nBA_DataSet.Players' 資料表。您可以視需要進行移動或移除。
  36. this.playersTableAdapter.Fill(this.nBA_DataSet.Players);
  37.  
  38. }
  39. public void FileToTeams()
  40. {
  41. string[] lineOfTeams = File.ReadAllLines("team.csv");
  42. foreach (var roughline in lineOfTeams)
  43. {
  44. string line = roughline.Replace("*", "");
  45. string[] tokens = line.Split(',');
  46. team newTeam = new team();
  47. newTeam.Rank = int.Parse(tokens[0]);
  48. newTeam.teamName = tokens[1].ToString();
  49. newTeam.GP = float.Parse(tokens[2]);
  50. newTeam.FG = float.Parse(tokens[3]);
  51. newTeam.FT = float.Parse(tokens[4]);
  52. newTeam.THREEPTM = float.Parse(tokens[5]);
  53. newTeam.PTS = float.Parse(tokens[6]);
  54. newTeam.REB = float.Parse(tokens[7]);
  55. newTeam.AST = float.Parse(tokens[8]);
  56. newTeam.ST = float.Parse(tokens[9]);
  57. newTeam.BLK = float.Parse(tokens[10]);
  58. newTeam.TO = float.Parse(tokens[11]);
  59. teamList.Add(newTeam);
  60. if (newTeam.teamName == "The Money Ball") {
  61. myteam.myteamscore = newTeam;
  62. }
  63. }
  64. }
  65.  
  66. public void FileToPlayers(string filename) {
  67. string[] lineOfPlayers = File.ReadAllLines(filename);
  68. foreach (var roughline in lineOfPlayers)
  69. {
  70. string line = roughline.Replace("*", "");
  71. string[] tokens = line.Split(',');
  72. player newPlayer = new player();
  73. newPlayer.ORANK = int.Parse(tokens[0]);
  74. newPlayer.GP = float.Parse(tokens[3]);
  75. string[] FG = tokens[5].Split('/');
  76. newPlayer.FGM = float.Parse(FG[0]);
  77. newPlayer.FGA = float.Parse(FG[1]);
  78. string[] FT = tokens[7].Split('/');
  79. newPlayer.FTM = float.Parse(FT[0]);
  80. newPlayer.FTA = float.Parse(FT[1]);
  81. newPlayer.THREEPTM = float.Parse(tokens[9]);
  82. newPlayer.PTS = float.Parse(tokens[10]);
  83. newPlayer.REB = float.Parse(tokens[11]);
  84. newPlayer.AST = float.Parse(tokens[12]);
  85. newPlayer.ST = float.Parse(tokens[13]);
  86. newPlayer.BLK = float.Parse(tokens[14]);
  87. newPlayer.TO = float.Parse(tokens[15]);
  88. playerList.Add(newPlayer);
  89. for (int i = 0; i < myteam.oranklist.Count(); i++) {
  90. if (newPlayer.ORANK == myteam.oranklist[i]) {
  91. myteam.myplayers.Add(newPlayer);
  92. }
  93. }
  94. }
  95. }
  96.  
  97. public void FileToMyPlayers()
  98. {
  99. string[] lineOfMyPlayers = File.ReadAllLines("myplayer.csv");
  100. foreach (var roughline in lineOfMyPlayers)
  101. {
  102. string line = roughline.Replace("*", "");
  103. string[] tokens = line.Split(',');
  104. myteam.oranklist.Add(int.Parse(tokens[0]));
  105. }
  106. }
  107.  
  108. public void FileToMyScore()
  109. {
  110. string[] lineOfMyScore = File.ReadAllLines("myscore.csv");
  111. foreach (var roughline in lineOfMyScore)
  112. {
  113. string line = roughline.Replace("*", "");
  114. string[] tokens = line.Split(',');
  115. if (tokens[0] == "The Money Ball")
  116. {
  117. myscore.TeamName = tokens[0];
  118. myscore.FGRank = float.Parse(tokens[1]);
  119. myscore.FTRank = float.Parse(tokens[2]);
  120. myscore.ThreeRank = float.Parse(tokens[3]);
  121. myscore.PTSRank = float.Parse(tokens[4]);
  122. myscore.REBRank = float.Parse(tokens[5]);
  123. myscore.ASTRank = float.Parse(tokens[6]);
  124. myscore.STRank = float.Parse(tokens[7]);
  125. myscore.BLKRank = float.Parse(tokens[8]);
  126. myscore.TORank = float.Parse(tokens[9]);
  127. myscore.Score = float.Parse(tokens[10]);
  128. }
  129. }
  130. }
  131.  
  132. public void inputname() {
  133. string[] lineofnames = File.ReadAllLines("playersnames.csv");
  134. foreach(var line in lineofnames){
  135. string[] tokens = line.Split(',');
  136. for(int q = 0; q < playerList.Count; q++) {
  137. if (((player)playerList[q]).ORANK == int.Parse(tokens[1])) {
  138. ((player)playerList[q]).name = tokens[0];
  139. if (tokens[2] == "out") {
  140. ((player)playerList[q]).status = "out";
  141. }
  142. }
  143. }
  144. }
  145. }
  146.  
  147. public void chk() {
  148. listBox1.Items.Clear();
  149. scoreboard newscore = myscore;
  150. team improvedteam = new team();
  151. //印出標題
  152. string r = "Deal,FG%,FT%,3PTM,PTS,REB,AST,ST,BLK,TO,Rank,FG%,FT%,3PTM,PTS,REB,AST,ST,BLK,TO";
  153. using (FileStream fs = new FileStream("result.csv", FileMode.Append, FileAccess.Write))
  154. using (StreamWriter sw = new StreamWriter(fs))
  155. {
  156. sw.WriteLine(r);
  157. }
  158. for (int i = 0; i < myteam.myplayers.Count; i++)
  159. {
  160. for (int j = 0; j < playerList.Count; j++)
  161. {
  162. if (((player)playerList[j]).status == "out" || ((player)playerList[j]).status == "mine") { continue; }
  163. if (checkBox1.Checked == true && (myteam.myplayers[i].ORANK < ((player)playerList[j]).ORANK + orankDiff)) { continue; }
  164. float allFGM = 820 * FGM / gameplayed + ((player)playerList[j]).FGM * gameleft - myteam.myplayers[i].FGM * gameleft;
  165. float allFGA = 820 * FGA / gameplayed + ((player)playerList[j]).FGA * gameleft - myteam.myplayers[i].FGA * gameleft;
  166. improvedteam.FG = allFGM / allFGA;
  167. float allFTM = 820 * FTM / gameplayed + ((player)playerList[j]).FTM * gameleft - myteam.myplayers[i].FTM * gameleft;
  168. float allFTA = 820 * FTA / gameplayed + ((player)playerList[j]).FTA * gameleft - myteam.myplayers[i].FTA * gameleft;
  169. improvedteam.FT = allFTM / allFTA;
  170. improvedteam.THREEPTM = 820 * myteam.myteamscore.THREEPTM / gameplayed + ((player)playerList[j]).THREEPTM * gameleft - myteam.myplayers[i].THREEPTM * gameleft;
  171. improvedteam.PTS = 820 * myteam.myteamscore.PTS / gameplayed + ((player)playerList[j]).PTS * gameleft - myteam.myplayers[i].PTS * gameleft;
  172. improvedteam.REB = 820 * myteam.myteamscore.REB / gameplayed + ((player)playerList[j]).REB * gameleft - myteam.myplayers[i].REB * gameleft;
  173. improvedteam.AST = 820 * myteam.myteamscore.AST / gameplayed + ((player)playerList[j]).AST * gameleft - myteam.myplayers[i].AST * gameleft;
  174. improvedteam.ST = 820 * myteam.myteamscore.ST / gameplayed + ((player)playerList[j]).ST * gameleft - myteam.myplayers[i].ST * gameleft;
  175. improvedteam.BLK = 820 * myteam.myteamscore.BLK / gameplayed + ((player)playerList[j]).BLK * gameleft - myteam.myplayers[i].BLK * gameleft;
  176. improvedteam.TO = 820 * myteam.myteamscore.TO / gameplayed + ((player)playerList[j]).TO * gameleft - myteam.myplayers[i].TO * gameleft;
  177. //算新的FG排名
  178. float passed = 1;
  179. float even = 0;
  180. for (int k = 0; k < teamList.Count; k++)
  181. {
  182. float eventcount = 0;
  183. if (improvedteam.FG > ((team)teamList[k]).FG) { passed++; }
  184. if (improvedteam.FG == ((team)teamList[k]).FG) { eventcount++; }
  185. if (eventcount != 0) { even += 1 / eventcount; }
  186. }
  187. if (even != 0) { imprvscore.FGRank = passed + 1 / even; }
  188. else{ imprvscore.FGRank = passed; }
  189. //算新的FT排名
  190. passed = 1;
  191. even = 0;
  192. for (int k = 0; k < teamList.Count; k++)
  193. {
  194. float eventcount = 0;
  195. if (improvedteam.FT > ((team)teamList[k]).FT) { passed++; }
  196. if (improvedteam.FT == ((team)teamList[k]).FT) { eventcount++; }
  197. if (eventcount != 0) { even += 1 / eventcount; }
  198. }
  199. if (even != 0) { imprvscore.FTRank = passed + 1 / even; }
  200. else{ imprvscore.FTRank = passed; }
  201. //算新的3PTM排名
  202. passed = 1;
  203. even = 0;
  204. for (int k = 0; k < teamList.Count; k++)
  205. {
  206. float eventcount = 0;
  207. if (improvedteam.THREEPTM/820 > ((team)teamList[k]).THREEPTM/((team)teamList[k]).GP) { passed++; }
  208. if (improvedteam.THREEPTM/820 == ((team)teamList[k]).THREEPTM / ((team)teamList[k]).GP) { eventcount++; }
  209. if (eventcount != 0) { even += 1 / eventcount; }
  210. }
  211. if (even != 0) { imprvscore.ThreeRank = passed + 1 / even; }
  212. else{ imprvscore.ThreeRank = passed; }
  213. //算新的PTS排名
  214. passed = 1;
  215. even = 0;
  216. for (int k = 0; k < teamList.Count; k++)
  217. {
  218. float eventcount = 0;
  219. if (improvedteam.PTS / 820 > ((team)teamList[k]).PTS / ((team)teamList[k]).GP) { passed++; }
  220. if (improvedteam.PTS / 820 == ((team)teamList[k]).PTS / ((team)teamList[k]).GP) { eventcount++; }
  221. if (eventcount != 0) { even += 1 / eventcount; }
  222. }
  223. if (even != 0) { imprvscore.PTSRank = passed + 1 / even; }
  224. else { imprvscore.PTSRank = passed; }
  225. //算新的REB排名
  226. passed = 1;
  227. even = 0;
  228. for (int k = 0; k < teamList.Count; k++)
  229. {
  230. float eventcount = 0;
  231. if (improvedteam.REB / 820 > ((team)teamList[k]).REB / ((team)teamList[k]).GP) { passed++; }
  232. if (improvedteam.REB / 820 == ((team)teamList[k]).REB / ((team)teamList[k]).GP) { eventcount++; }
  233. if (eventcount != 0) { even += 1 / eventcount; }
  234. }
  235. if (even != 0) { imprvscore.REBRank = passed + 1 / even; }
  236. else { imprvscore.REBRank = passed; }
  237. //算新的AST排名
  238. passed = 1;
  239. even = 0;
  240. for (int k = 0; k < teamList.Count; k++)
  241. {
  242. float eventcount = 0;
  243. if (improvedteam.AST / 820 > ((team)teamList[k]).AST / ((team)teamList[k]).GP) { passed++; }
  244. if (improvedteam.AST / 820 == ((team)teamList[k]).AST / ((team)teamList[k]).GP) { eventcount++; }
  245. if (eventcount != 0) { even += 1 / eventcount; }
  246. }
  247. if (even != 0) { imprvscore.ASTRank = passed + 1 / even; }
  248. else { imprvscore.ASTRank = passed; }
  249. //算新的ST排名
  250. passed = 1;
  251. even = 0;
  252. for (int k = 0; k < teamList.Count; k++)
  253. {
  254. float eventcount = 0;
  255. if (improvedteam.ST / 820 > ((team)teamList[k]).ST / ((team)teamList[k]).GP) { passed++; }
  256. if (improvedteam.ST / 820 == ((team)teamList[k]).ST / ((team)teamList[k]).GP) { eventcount++; }
  257. if (eventcount != 0) { even += 1 / eventcount; }
  258. }
  259. if (even != 0) { imprvscore.STRank = passed + 1 / even; }
  260. else { imprvscore.STRank = passed; }
  261. //算新的BLK排名
  262. passed = 1;
  263. even = 0;
  264. for (int k = 0; k < teamList.Count; k++)
  265. {
  266. float eventcount = 0;
  267. if (improvedteam.BLK / 820 > ((team)teamList[k]).BLK / ((team)teamList[k]).GP) { passed++; }
  268. if (improvedteam.BLK / 820 == ((team)teamList[k]).BLK / ((team)teamList[k]).GP) { eventcount++; }
  269. if (eventcount != 0) { even += 1 / eventcount; }
  270. }
  271. if (even != 0) { imprvscore.BLKRank = passed + 1 / even; }
  272. else { imprvscore.BLKRank = passed; }
  273. //算新的TO排名
  274. passed = 1;
  275. even = 0;
  276. for (int k = 0; k < teamList.Count; k++)
  277. {
  278. float eventcount = 0;
  279. if (improvedteam.TO / 820 < ((team)teamList[k]).TO / ((team)teamList[k]).GP) { passed++; }
  280. if (improvedteam.TO / 820 == ((team)teamList[k]).TO / ((team)teamList[k]).GP) { eventcount++; }
  281. if (eventcount != 0) { even += 1 / eventcount; }
  282. }
  283. if (even != 0) { imprvscore.TORank = passed + 1 / even; }
  284. else { imprvscore.TORank = passed; }
  285.  
  286. imprvscore.Score = imprvscore.FGRank
  287. + imprvscore.FTRank
  288. + imprvscore.ThreeRank
  289. + imprvscore.PTSRank
  290. + imprvscore.REBRank
  291. + imprvscore.ASTRank
  292. + imprvscore.STRank
  293. + imprvscore.BLKRank
  294. + imprvscore.TORank;
  295.  
  296. //印出結果
  297.  
  298.  
  299. if (imprvscore.Score >= myscore.Score + float.Parse(textBox7.Text))
  300. if (((player)playerList[j]).status != "mine")
  301. {
  302. string s = ((player)playerList[j]).ORANK.ToString() + " "
  303. +((player)playerList[j]).name + " vs "
  304. + myteam.myplayers[i].ORANK.ToString() + " "
  305. + myteam.myplayers[i].name + ","
  306. + imprvscore.FGRank.ToString() + ","
  307. + imprvscore.FTRank.ToString() + ","
  308. + imprvscore.ThreeRank.ToString() + ","
  309. + imprvscore.PTSRank.ToString() + ","
  310. + imprvscore.REBRank.ToString() + ","
  311. + imprvscore.ASTRank.ToString() + ","
  312. + imprvscore.STRank.ToString() + ","
  313. + imprvscore.BLKRank.ToString() + ","
  314. + imprvscore.TORank.ToString() + ","
  315. + imprvscore.Score.ToString() + ","
  316. + improvedteam.FG.ToString() + ","
  317. + improvedteam.FT.ToString() + ","
  318. + improvedteam.THREEPTM.ToString() + ","
  319. + improvedteam.PTS.ToString() + ","
  320. + improvedteam.REB.ToString() + ","
  321. + improvedteam.AST.ToString() + ","
  322. + improvedteam.ST.ToString() + ","
  323. + improvedteam.BLK.ToString() + ","
  324. + improvedteam.TO.ToString();
  325. s.Replace("?", " ");
  326. using (FileStream fm = new FileStream("result.csv", FileMode.Append, FileAccess.Write))
  327. using (StreamWriter sm = new StreamWriter(fm))
  328. {
  329. sm.WriteLine(s);
  330. }
  331. listBox1.Items.Add(s);
  332. }
  333. }
  334. }
  335. listBox1.Items.Add("End");
  336.  
  337. }
  338.  
  339.  
  340. class team
  341. {
  342. public int Rank;
  343. public string teamName;
  344. public float GP;
  345. public float FG;
  346. public float FT;
  347. public float THREEPTM;
  348. public float PTS;
  349. public float REB;
  350. public float AST;
  351. public float ST;
  352. public float BLK;
  353. public float TO;
  354. }
  355.  
  356. class player
  357. {
  358. public int ORANK;
  359. public string name = "none";
  360. public float GP;
  361. public float FGM;
  362. public float FGA;
  363. public float FTM;
  364. public float FTA;
  365. public float THREEPTM;
  366. public float PTS;
  367. public float REB;
  368. public float AST;
  369. public float ST;
  370. public float BLK;
  371. public float TO;
  372. public string status = "in";
  373. }
  374.  
  375. class ateam {
  376. public List<int> oranklist = new List<int>();
  377. public List<player> myplayers = new List<player>();
  378. public team myteamscore = new team();
  379.  
  380. }
  381.  
  382. class scoreboard {
  383. public string TeamName;
  384. public float FGRank;
  385. public float FTRank;
  386. public float ThreeRank;
  387. public float PTSRank;
  388. public float REBRank;
  389. public float ASTRank;
  390. public float STRank;
  391. public float BLKRank;
  392. public float TORank;
  393. public float Score;
  394. }
  395.  
  396.  
  397.  
  398. private void button1_Click(object sender, EventArgs e)
  399. {
  400. if (File.Exists("Result.csv")) {
  401. File.Delete("Result.csv");
  402. }
  403. FileToMyPlayers();
  404. FileToTeams();
  405. gameplayed = float.Parse(textBox1.Text);
  406. gameleft = (820-gameplayed) / 13;
  407. orankDiff = int.Parse(textBox2.Text);
  408. FGM = float.Parse(textBox3.Text);
  409. FGA = float.Parse(textBox4.Text);
  410. FTM = float.Parse(textBox5.Text);
  411. FTA = float.Parse(textBox6.Text);
  412. FileToPlayers(textBox8.Text);
  413. FileToMyScore();
  414. inputname();
  415. chk();
  416. }
  417.  
  418. private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  419. {
  420.  
  421. }
  422.  
  423. private void button2_Click(object sender, EventArgs e)
  424. {
  425. OpenFileDialog file = new OpenFileDialog();
  426. file.ShowDialog();
  427. textBox8.Text = file.SafeFileName;
  428. }
  429.  
  430. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  431. {
  432.  
  433. }
  434.  
  435. private void button3_Click(object sender, EventArgs e)
  436. {
  437. try
  438. {
  439. DataRow dr = nBA_DataSet.Tables["Players"].NewRow();
  440. dr["ORANK"] = 1;
  441. dr["NAME"] = "Michael Jordan";
  442. dr["GP"] = 52;
  443. dr["FGM"] = 18.6;
  444. dr["FGA"] = 25.4;
  445. dr["FTM"] = 6.3;
  446. dr["FTA"] = 8.0;
  447. dr["THREEPTM"] = 5.2;
  448. dr["PTS"] = 38.6;
  449. dr["REB"] = 10.6;
  450. dr["AST"] = 7.6;
  451. dr["ST"] = 4.6;
  452. dr["BLK"] = 3.6;
  453. dr["TO"] = 2.6;
  454. dr["STATUS"] = "in";
  455. nBA_DataSet.Tables["Players"].Rows.Add(dr);
  456. playersTableAdapter.Update(nBA_DataSet);
  457. MessageBox.Show("insert success");
  458. }
  459. catch (InvalidCastException error)
  460. {
  461. MessageBox.Show(error.Message.ToString());
  462. }
  463. }
  464. }
  465. }
  466.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(4,14): error CS0234: The type or namespace name `Data' does not exist in the namespace `System'. Are you missing an assembly reference?
prog.cs(8,24): error CS0234: The type or namespace name `Tasks' does not exist in the namespace `System.Threading'. Are you missing an assembly reference?
prog.cs(9,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
Compilation failed: 3 error(s), 0 warnings
stdout
Standard output is empty