双淘汰赛的数据结构 [英] Data structure for Double Elmination Tournament

查看:90
本文介绍了双淘汰赛的数据结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在转换我的Tournament Organizer软件,该软件允许创建和操纵Double Elimination Tournaments,使用MVVM设计模式,以便可以更轻松地对其进行测试.为此,我要从UI中的一些代码中分离出模型",这些代码直接操纵括号结构.

I am in the process of converting my Tournament Organizer software, which allows the creation and manipulation of Double Elimination Tournaments, to use the MVVM design pattern so that it can be more easily tested. In doing so, I'm separating out the 'model' from some code in the UI that directly manipulates the bracket structure.

这将是我编写的用于处理比赛的软件的第三次迭代.第一个是用PHP编写的,并将数据存储在数据库中.第二个版本是我制作的WPF版本,它将数据存储在内存中,然后将其序列化为XML文件.但是,在这两个版本中,我都认为实现的某些方面不干净,而且似乎违反了DRY的法则.

This will be the third iteration of software I've written to handle tournaments. The first was written in PHP and stored the data in a database. The second version is the WPF version I made, and it stores the data in memory, and then serializes it to an XML file. However, in both versions, there are aspects of the implementation that I feel aren't clean, and seem like they break the law of DRY.

如果您是从头开始创建数据结构以处理双消除括号,您将如何做?

请注意,它并不需要能够通过算法自动生成括号(我现在是通过4/8/16/32人从预先制作的双重淘汰赛中加载任务)设置比赛获胜者并通过括号推进"他们的主要用例.

Note that it doesn't need to be able to automatically generate the brackets algorithmically (loading from a pre-made double-elimination with 4/8/16/32 people is how I'm doing it now), just the main use case of setting winners of matches and 'advancing' them through the bracket.

为了清楚起见,数据结构需要处理两次淘汰赛,因此,一场比赛的获胜者可能最终会与另一场比赛的输家竞争.

To make it clear, the data structure needs to handle double elimination tournaments, so potentially, the winner of one match could end up competing against the loser of another.

推荐答案

我对此的解决方案是拥有两组数据结构.一个用于支架,一个用于座椅.

My solution to this was to have two sets of data structures. One for the bracket part, and one for the seats.

class Match
{
    string Id;
    MatchSeat red;
    MatchSeat blue;
    MatchSeat winner;
    MatchSeat loser;
}

class MatchSeat
{
    string Id;
    Entry Entry;
}

然后进行设置,我做了一些辅助函数,这些函数使用了括号信息并构建了结构.

And then to set it up, I made some helper functions that took the bracket information and built the structures.

{ "1", "seed1", "seed4", "W1", "L1" },
{ "2", "seed2", "seed3", "W2", "L2" },
{ "3", "W1", "W2", "W3", "L3" },
{ "4", "L1", "L2", "W4", "L4" },
{ "5", "W4", "L3", "W5", "L5" },
{ "F", "W3", "W5", "WF", "WF" }

然后,当种子和获胜者/失败者填写完毕时,该值仅设置在一个位置.

Then when the seeds and winners/losers are filled out, the value only gets set in one place.

这篇关于双淘汰赛的数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆