大叔
加入日期: 2005-01-10
帖子: 2947
现金: 72 盾
|
回复: ChinaSpurs.com FBA选秀顺位确定办法
为公正起见,特公布抽签程序的源代码,使用Visual C# 2005
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace lottery
{
///
/// Form1 的摘要说明。
///
public class Form1 : System.Windows.Forms.Form
{
///
/// 必需的设计器变量。
///
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBox5;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox textBox6;
private System.Windows.Forms.TextBox textBox7;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.TextBox textBox8;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.TextBox textBox9;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.TextBox textBox10;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.TextBox textBox11;
private System.Windows.Forms.TextBox textBox12;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.TextBox textBox13;
private System.Windows.Forms.Label label13;
private System.Windows.Forms.Label label14;
private System.Windows.Forms.TextBox textBox14;
private System.Windows.Forms.Label label15;
private System.Windows.Forms.TextBox textBox15;
private System.Windows.Forms.TextBox textBox16;
private System.Windows.Forms.Label label16;
private System.Windows.Forms.TextBox textBox17;
private System.Windows.Forms.Label label17;
private System.Windows.Forms.Label label18;
private System.Windows.Forms.TextBox textBox18;
private System.Windows.Forms.Button btnBegin;
private System.Windows.Forms.Label label19;
private GroupBox groupBox1;
private RadioButton rbAdmiral;
private RadioButton rbIceman;
private Label label20;
private ComboBox cmbPlayers;
private ArrayList lots; // 保存所有种子数
private Player[] players; // 所有选手
private TextBox[] txts; // 保存所有文本框,以便于用循环方式进行处理
private int player_count = 16; // 选手数量
private bool isIceman = true; // 表示当前所选择的是否为Iceman联盟,由于Iceman存在优先级,所以要特别处理
private int seed_per_player = 80;
private Label lblTime; // 每位普通选手的种子数,默认为80
private int seed_count = 1380; // 11 * 80 + 5 * 100, 100是乐透选手的种子数
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
txts = new TextBox[18];
txts[0] = this.textBox1;
txts[1] = this.textBox2;
txts[2] = this.textBox3;
txts[3] = this.textBox4;
txts[4] = this.textBox5;
txts[5] = this.textBox6;
txts[6] = this.textBox7;
txts[7] = this.textBox8;
txts[8] = this.textBox9;
txts[9] = this.textBox10;
txts[10] = this.textBox11;
txts[11] = this.textBox12;
txts[12] = this.textBox13;
txts[13] = this.textBox14;
txts[14] = this.textBox15;
txts[15] = this.textBox16;
txts[16] = this.textBox17;
txts[17] = this.textBox18;
this.cmbPlayers.SelectedIndex = 3; // 16
}
///
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
///
/// 应用程序的主入口点。
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
// 初始化种子
public void InitLottery()
{
if (this.isIceman)
this.seed_count = 1380;
else
this.seed_count = this.player_count * seed_per_player;
lots = new ArrayList( this.seed_count );
Random ran = new Random();
int count = 0;
while( count < this.seed_count )
{
int k = ran.Next( 1, this.seed_count + 1 );
if( !lots.Contains( k ))
{
count ++;
lots.Add( k );
}
}
players = new Player[18];
players[0] = new Player( "A");
players[1]= new Player( "B");
players[2]= new Player( "C");
players[3]= new Player( "D");
players[4]= new Player( "E");
players[5]= new Player( "F");
players[6]= new Player( "G");
players[7]= new Player( "H");
players[8]= new Player( "I");
players[9]= new Player( "J");
players[10]= new Player( "K");
players[11]= new Player( "L");
players[12]= new Player( "M");
players[13]= new Player( "N");
players[14]= new Player( "O");
players[15]= new Player( "P");
players[16] = new Player("Q");
players[17] = new Player("R");
if (this.isIceman)
{
players[11].isLot = true;
players[12].isLot = true;
players[13].isLot = true;
players[14].isLot = true;
players[15].isLot = true;
}
for (int m = 0; m < seed_per_player; m++)
{
for( int n = 0; n < this.player_count ; n ++ )
{
players[n].seeds.Add( lots[m*this.player_count + n]);
}
}
// 如果是Iceman联盟,增加乐透区选手的种子数
if (this.isIceman)
{
for (int m = 0; m < 10; m++)
{
for (int n = 0; n < 5; n++)
{
players[11 + n].seeds.Add(lots[1200 + m * 5 + n]);
}
}
}
}
// 前四轮乐透区选秀
public void PriorityPick()
{
int result = 0;
Random ran = new Random();
bool selected = false;
// 前四轮为乐透选秀
for( int p = 0; p < 4; p ++ )
{
while( true )
{
selected = false;
result = ran.Next( 1, this.seed_count + 1 );
for( int i = 0; i < this.player_count ; i ++ )
{
if( players[i].seeds.Contains( result ) )
{
if( players[i].selected == false )
{
players[i].selected = true;
selected = true;
this.txts[p].Text = players[i].name;
// 每轮之后,乐透选手的种子数减去5
for (int j = 11; j < player_count; j++)
{
players[j].TrimSeeds(5);
}
break;
}
else
break;
}
}
if( selected )
break;
}
}
}
// 非乐透选秀,从第start+1轮直到第end轮
public void EvenPick( int start, int end)
{
int result = 0;
Random ran = new Random();
bool selected = false;
for( int p = start; p < end; p ++ )
{
while( true )
{
selected = false;
result = ran.Next( 1, this.seed_count + 1 );
for( int i = 0; i < this.player_count ; i ++ )
{
if( players[i].seeds.Contains( result ) )
{
if( players[i].selected == false )
{
players[i].pick = p;
players[i].selected = true;
selected = true;
this.txts[p].Text = players[i].name;
break;
}
else
break;
}
}
if( selected )
break;
}
}
}
private void rbIceman_CheckedChanged(object sender, EventArgs e)
{
this.ClearAllText();
if (this.rbAdmiral.Checked)
{
this.cmbPlayers.Enabled = true;
this.cmbPlayers.SelectedIndex = 4;
this.isIceman = false;
this.player_count = 18; // 默认联盟人数为18
}
else
{
this.cmbPlayers.SelectedIndex = 0;
this.cmbPlayers.Enabled = false;
this.isIceman = true;
this.player_count = 16;
}
}
private void btnBegin_Click(object sender, EventArgs e)
{
this.lblTime.Text = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
this.ClearAllText();
this.InitLottery();
if (this.isIceman)
{
this.PriorityPick();
this.EvenPick(4, this.player_count);
}
else
{
this.EvenPick(0, this.player_count);
}
}
private void cmbPlayers_SelectedIndexChanged(object sender, EventArgs e)
{
// Iceman规定为16名选手,Admiral联盟的人数可以是10-18人
this.player_count = Convert.ToInt32(this.cmbPlayers.Text);
}
// 清空所有文本框的内容
private void ClearAllText()
{
for (int i = 0; i < this.txts.Length; i++)
{
this.txts[i].Text = "";
}
this.lblTime.Text = "";
}
}
public class Player
{
public int pick;
public bool selected;
public bool isLot;
public string name;
public ArrayList seeds;
public Player( string nam )
{
selected = false;
name = nam;
seeds = new ArrayList( 100 );
}
public void TrimSeeds( int seed )
{
if( this.isLot )
{
this.seeds.RemoveRange( 0, seed );
}
}
}
}
|