威尼斯人线上娱乐

开头了然,中华夏族民共和国象棋引擎的C

3 4月 , 2019  

威尼斯人线上娱乐 1

0 序

威尼斯人线上娱乐,开始用 HTC Vive
做项目,由于
OpenVR
并从未提供用于 Unity3D 的 C♯ 文书档案(只提供了C++ API
文档),所以想写贰个“第3方”的
OpenVQashqai C♯ API 文书档案,借此机会抓牢姿势和档次。

由于小编的档次十分低,由此可见接下去自然会赶上很多标题,望读者海涵,若是有怎么样写得语无伦次的地点请一定提出并往死里喷作者,教笔者人生的经验。虽然我认为没人会读这东西。

以前写的中中原人民共和国象棋引擎的C#源程序,可在VS20第10中学编写翻译运营,由于个人精力有限,难以实现后续的开销工作,借使哪个人感兴趣,请关切微信公众号(“申龙斌的次序人生”,ID:slbGTD),发送后台消息“象棋引擎”,可收取源代码和连锁资料的下载链接。并请报告自身你的人名,并且只要您改改代码后参赛请加上自个儿的名字就行了。

  1. g二o二〇一四0430下的csparse文件夹内的CMakeLists.txt

    cmake_minimum_required(VERSION 2.6)

    PROJECT(csparse)

    SET(CMAKE_C_FLAGS_RELEASE “-O3 -DNDEBUG”)
    #设置 G2O_LGPL_LIB_TYPE STATIC就算想制造静态的csparse库

    ADD_LIBRARY(csparse ${G2O_LGPL_LIB_TYPE} cs_add.c cs_amd.c cs_chol.c cs_cholsol.c cs_compress.c cs_counts.c cs_cumsum.c cs_dfs.c cs_dmperm.c cs_droptol.c cs_dropzeros.c
    cs_dupl.c cs_entry.c cs_ereach.c cs_etree.c cs_fkeep.c cs_gaxpy.c cs_happly.c cs_house.c cs_ipvec.c cs_leaf.c cs_load.c cs_lsolve.c cs_ltsolve.c cs_lu.c cs_lusol.c
    cs_malloc.c cs_maxtrans.c cs_multiply.c cs_norm.c cs_permute.c cs_pinv.c cs_post.c cs_print.c cs_pvec.c cs_qr.c cs_qrsol.c cs_randperm.c cs_reach.c cs_scatter.c cs_scc.c
    cs_schol.c cs_spsolve.c cs_sqr.c cs_symperm.c cs_tdfs.c cs_transpose.c cs_updown.c cs_usolve.c cs_util.c cs_utsolve.c cs_api.h )

    SET_TARGET_PROPERTIES(csparse PROPERTIES OUTPUT开头了然,中华夏族民共和国象棋引擎的C。_NAME ${LIB_PREFIX}ext_csparse)
    IF (UNIX)
    TARGET_LINK_LIBRA奥迪Q7IES(csparse m)
    ENDIF()
    #输出路径
    INSTALL(TA中华VGETS csparse
      RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
      LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
      ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib )
    #安装路径
    FILE(GLOB headers “${CMAKE_CURRENT_SOURCE_DIR}/.h” “${CMAKE_CURRENT_SOURCE_DIR}/.hpp”)
    INSTALL(FILES ${headers} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/EXTERNAL/csparse)

    # Set up the variables
    SET(CSPARSE_LIBRARY “$”)
    SET(CSPARSE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH “Include directory for CSparse” FORCE)
    SET(CSPARSE_LIBRARY ${CSPARSE_LIBRARY} CACHE FILEPATH “CSparse library” FORCE)

    #SET(CSPARSE_FOUND TRUE PARENT_SCOPE)
    #MESSAGE(“CSPARSE_LIBRARY = ${CSPARSE_LIBRARY}”)
    #MESSAGE(“CSPARSE_INCLUDE_DIR = ${CSPARSE_INCLUDE_DIR}”)

威尼斯人线上娱乐 2威尼斯人线上娱乐 3

1 对此OpenV酷威的启幕认识

OpenV逍客 是由 Valve 集团支付的1套 VSportage 设备通用 API ,换而言之不管是
Oculus Rift 或 三星 Vive 甚至是另外 V汉兰达 设备,都不再须要动用产商提供的
SDK
就能够展开销付,有种打算1统天下的范儿。那套 API
尚未开源于是实际贯彻未知。(由于 Vive 和 Oculus Rift
的规律看似壹样只是事实上对于画面包车型地铁拍卖大相径庭,依据自己首当其冲的瞎猜,笔者以为那套
API 只是帮大家在原本设备产商提供的 SDK
上又达成了贰个力所能及透过联合接口访问的用空想来欺骗别人层来,应该不是什么黑科学和技术大概

OpenV奥迪Q7 文件夹的布局大体上如下:

\openvr
    \bin                用于各平台的dll、pdb文件
    \headers            用于 C++(.h) 和 C♯(.cs) 的头文件
                       (是根据本文件夹下的 openvr_api.json 自动生成的,不要手动编辑)
    \lib                用于各平台的lib文件
    \samples            C++、Unity 范例
    \unity_package    用于 Unity 的 Package

unity_package 是之后研讨的首要。

近来完成的劳作:

 

using System.Collections.Generic;
namespace Chart
{
    public class Program
    {
        static void Main(string[] args)
        {
            Chart chart = new Chart();
            ChartType chartType = ChartType.Histogram;
            string path = @"..\..\JSON.json";
            DataSource dataSource = new JsonDataSource();
            List<Composition> Compositions = dataSource.GetDataList(path);
            chart.Compositions.AddRange(Compositions);
            chart.Draw(chartType);
            chart.Save();
        }
    }
}

2 OpenVR Unity Package

OpenVRubicon Unity Package 包涵以下脚本内容:

  • \Plugins
    • openvr_api.cs
  • \SteamVR
    • \Editor
      • SteamVR_Editor.cs
      • SteamVR_RenderModelEditor.cs
      • SteamVR_Settings.cs
      • SteamVR_SkyboxEditor.cs
      • SteamVR_Update.cs
    • \Scripts
      • SteamVR.cs
      • SteamVR_Camera.cs
      • SteamVR_CameraFlip.cs
      • SteamVR_CameraMask.cs
      • SteamVR_Controller.cs
      • SteamVR_ControllerManager.cs
      • SteamVR_Ears.cs
      • SteamVR_ExternalCamera.cs
      • SteamVR_Fade.cs
      • SteamVR_Frustum.cs
      • SteamVR_GameView.cs
      • SteamVR_IK.cs
      • SteamVR_LoadLevel.cs
      • SteamVR_Menu.cs
      • SteamVR_Overlay.cs
      • SteamVR_PlayArea.cs
      • SteamVR_Render.cs
      • SteamVR_RenderModel.cs
      • SteamVR_Skybox.cs
      • SteamVR_SphericalProjection.cs
      • SteamVR_Stats.cs
      • SteamVR_Status.cs
      • SteamVR_StatusText.cs
      • SteamVR_TestController.cs
      • SteamVR_TrackedObject.cs
      • SteamVR_UpdatePoses.cs
      • SteamVR_Utils.cs
    • \Extras
      • SteamVR_GazeTracker.cs
      • SteamVR_LaserPointer.cs
      • SteamVR_Teleporter.cs
      • SteamVR_TestThrow.cs
      • SteamVR_TrackedController.cs

事实上,只有 \Plugins 中的 open_api.cs 是直接与 OpenV本田CR-V打交道的,是它把 OpenVKoleos 全体的 API
都暴流露来,并且注解了有的用以与其展开置换的数据结构。

\Scripts 下是合法为我们落实的1些力所能及处理 OpenV奇骏中的原始数据的主意,和力所能及有利于的在 Unity
中调用的秘诀,官方的说法是“推荐我们修改并建议申报”(You are encouraged
to modify these to suit your project’s unique needs, and provide
feedback
),当然,大家此番的大旨是看懂它,所以不作修改就我这水平,能看懂就不错了

用过Unity的都理解 \Editor 下是有的编辑器脚本,\Extras
下是部分归纳的行使,所以就不多提了。可是值得提的是,Valve
还写了贰个自动检验 Project Settings
等装置是还是不是有标题且能够一键自动配置的编辑器扩展工具,简直比 Oculus
高到不知道哪里去了

关于详细内容请参见 readme 此处不再叙述。


下一篇,大家主要商量 openvr_api.cs,了解 class OpenVR{} 中的方法。

壹)着法生成

Program.cs

二)简单的alphabeta算法,协理置换表

 

叁)能够读取一群PGN文件,生成开局库

威尼斯人线上娱乐 4威尼斯人线上娱乐 5

4)解析ucci命令

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
namespace Chart
{
    public class Chart
    {
        private Bitmap bmp = new Bitmap(600, 600);
        List<Composition> composition = new List<Composition>();
        public List<Composition> Compositions { get { return composition; } }
        private float width;

        private float Width
        {
            get
            {
                int sum = 0;
                foreach (var composition in Compositions)
                {
                    sum += composition.DataPoints.Count + 1;
                }
                width = (float)420 / sum;
                return width;
            }
        }

        public void Draw(ChartType chartType)
        {
            Series series;

            switch (chartType)
            {
                case ChartType.LineChart:
                    series = new LineSeries();
                    break;

                case ChartType.Histogram:
                    series = new HistogramSeries();
                    break;

                case ChartType.PieChart:
                    series = new PieSeries();
                    break;

                default:
                    throw new ArgumentOutOfRangeException("Nonexistent ChartType!");
            }

            foreach (var comPosition in Compositions)
            {
                series.Legend.Add(comPosition.Name);
            }

            Platform platform = new Windows(bmp);

            series.Draw(Width, platform, Compositions);
        }

        public void Save()
        {
            bmp.Save(@"..\..\1.bmp");
            Process.Start(@"..\..\1.bmp");
        }
    }
}

伍)有1个对阵测试程序

Chart.cs

陆)基本的单元测试

威尼斯人线上娱乐 6威尼斯人线上娱乐 7

次第当前全体是托管代码,还一贯不考虑品质优化。

using System.Collections;
using System.Collections.Generic;
using System.Drawing;
namespace Chart
{
    public abstract class Series
    {
        ArrayList legend = new ArrayList();
        public ArrayList Legend { get { return legend; } set { } }

        protected PointF PointFormLarge;
        protected PointF PointFormSmall;

        private void DrawChart(Platform g)
        {
            g.FillRectangle(g.WBrush, 20, 20, 580, 500);
        }

        protected abstract void DrawCore(float width, Platform g, List<Composition> Compositions);

        public void Draw(float width, Platform g, List<Composition> Compositions)
        {
            PointFormLarge = new PointF(width * Compositions.Count + width, 0);
            PointFormSmall = new PointF(width, 0);
            DrawChart(g);
            DrawCore(width, g, Compositions);
        }
    }
}

威尼斯人线上娱乐 8

Series.cs

一切源代码能够编写翻译,某个公文有双重,以源代码中的工程文件的为准。

威尼斯人线上娱乐 9威尼斯人线上娱乐 10

除开源代码之外,还有收集到的1些休戚相关随想可以壹并提供。

using System.Collections.Generic;
using System.Drawing;
using System;
namespace Chart
{
    public class HistogramSeries : Series
    {

        private void DrawAxes(Platform g)
        {
            g.DrawLine(g.Rpen, new Point(100, 40), new Point(100, 420));
            g.DrawLine(g.Rpen, new Point(100, 40), new Point(90, 50));
            g.DrawLine(g.Rpen, new Point(100, 40), new Point(110, 50));
            g.DrawLine(g.Rpen, new Point(100, 420), new Point(570, 420));
            g.DrawLine(g.Rpen, new Point(570, 420), new Point(560, 410));
            g.DrawLine(g.Rpen, new Point(570, 420), new Point(560, 430));

            g.DrawString("月考成绩", g.LargeFont, g.Bbrush, new RectangleF(300, 30, 170, 50));
            g.DrawString("科目", g.LargeFont, g.Bbrush, new RectangleF(530, 450, 100, 40));
            g.DrawString("成绩", g.LargeFont, g.Bbrush, new RectangleF(40, 30, 40, 40));

            for (int i = 0; i < 5; i++)
            {
                g.DrawLine(g.BlackPen, new Point(100, 60 + 72 * i), new Point(570, 60 + 72 * i));
            }
        }

        private void DrawLegend(Platform g)
        {
            int LegendWidth = 250 / (Legend.Count - 1);
            int StringX = 50;
            int LegendX = StringX + 60;
            int k = 0;
            foreach (string legend in Legend)
            {
                switch (k)
                {
                    case 0:
                        g.Brush = Brushes.Blue;
                        break;
                    case 1:
                        g.Brush = Brushes.Red;
                        break;
                    case 2:
                        g.Brush = Brushes.Yellow;
                        break;
                    case 3:
                        g.Brush = Brushes.Green;
                        break;
                }
                g.DrawString(legend, g.LargeFont, Brushes.Blue, StringX, 480);
                Rectangle rect = new Rectangle(LegendX, 480, LegendWidth * 2 / 3, 20);
                g.FillRectangle(g.Brush, rect);

                StringX += 550 / Legend.Count;
                LegendX = StringX + 60;
                k++;
            }
        }



        protected override void DrawCore(float width, Platform g, List<Composition> Compositions)
        {
            DrawAxes(g);
            DrawLegend(g);
            foreach (var datapoint in Compositions[0].DataPoints)
            {
                g.DrawString(datapoint.XValue, g.LargeFont, g.Bbrush, 120, 430);
                g.TranslateTransform(PointFormLarge.X, PointFormLarge.Y);
            }
            g.ResetTransform();

            int YValueMax = 0;
            foreach (var composition in Compositions)
            {
                if (YValueMax <= composition.Max)
                {
                    YValueMax = composition.Max;
                }
            }

            g.YRatioScale = 370 / YValueMax;


            for (int i = 0; i <= 5; i++)
            {
                g.DrawString(Math.Ceiling(360/5/ g.YRatioScale*(5-i)).ToString(), g.LargeFont, g.BlackBrush, new RectangleF(80, 50 + 72 * i, 50, 50));
            }




            void DrawRectangle(float x, float y, float Width, float height, Composition composition)
            {
                Rectangle rect = new Rectangle((int)x, (int)y, (int)width, (int)height);
                g.FillRectangle(composition.BrushColor, rect);
            }
            int j = 1;
            foreach (var composition in Compositions)
            {
                Compositions[0].BrushColor = Brushes.Blue;
                Compositions[1].BrushColor = Brushes.Red;
                Compositions[2].BrushColor = Brushes.Yellow;
                foreach (var datapoint in composition.DataPoints)
                {
                    DrawRectangle(120, 420 - datapoint.YValue * g.YRatioScale, width, datapoint.YValue * g.YRatioScale, composition);
                    g.DrawString(datapoint.YValue.ToString(), g.SmallFont, Brushes.Red, 120, 420 - datapoint.YValue * g.YRatioScale - 15);
                    g.TranslateTransform(PointFormLarge.X, PointFormLarge.Y);
                }
                g.ResetTransform();
                for (int i = 0; i < j; i++)
                {
                    g.TranslateTransform(PointFormSmall.X, PointFormSmall.Y);
                }
                j++;
            }
            g.ResetTransform();
        }
    }
}

PonderNet
│  PonderNet.sln
├─BitBoardBase   本来是想用位棋盘的,后来看来壹篇诗歌(200捌.Reul.New
Architectures in Computer Chess),改用一7×1四的数组表示法
│    BitHack64.cs
│    Board.cs
│    BoardUtil.cs
│    Board_Const.cs
│    Board_Makemove.cs
│    Fen.cs
│    Move.cs
│    MoveGenerator.cs
│    MoveGenerator_Preset.cs
│    MoveNotation.cs
│    PgnUtil.cs
│    RandomMersenneTwister.cs
│    TraceAndTestImpact.testsettings
│    Zobrist.cs
│         
├─Perft    用来表达着法程序生成的工具
│    Program.cs
│         
├─Ponder.OpeningBook   用来扭转开局库的工具
│    Program.cs
│         
├─PonderEngine  引擎
│    Evaluator.cs
│    MoveGenerator.cs
│    MoveGenerator_Preset.cs
│    OpeningBook.cs
│    PonderEngine.cs
│    PonderMain.cs
│    SearchTT.cs
│    SimpleSearch.cs
│    TranspositionTable.cs
│    UcciCommand.cs   能够分辨部分简短的ucci命令
│   
│         
├─PonderGame   用于与别的引擎对战的次第,也得以协调与温馨对战
│   Engine.cs
│   EngineProcess.cs
│   ExeProcess.cs
│   PonderGame.cs
│   PonderGameMain.cs
│   Settings.cs
│         
├─TestBitBoardBase  单元测试,首要针对着法生成
│    BoardTest.cs
│    MoveGeneratorTest.cs
│    TestBitBoardBase.csproj
│    TestChineseChess.csproj
│         
└─TestPonderEngine  单元测试,首要针对引擎的阿尔法beta搜索算法
      MoveGeneratorTest.cs
      PonderEngineTest.cs
      SimpleSearchTest.cs
      TestPonderEngine.csproj
      UnitTest_SearchTT.cs

Histogram.cs

威尼斯人线上娱乐 11威尼斯人线上娱乐 12

using System.Drawing;
namespace Chart
{
    public abstract class Platform
    {
        public abstract void FillRectangle(Brush b, int x, int y, int width, int height);
        public abstract void DrawLine(Pen pen, Point pt1, Point pt2);
        public abstract void DrawString(string s, Font font, Brush brush, RectangleF layoutRectangle);
        public abstract void DrawString(string s, Font font, Brush brush, float x, float y);
        public abstract void FillRectangle(Brush brush, Rectangle rect);
        public abstract void TranslateTransform(float dx, float dy);
        public abstract void ResetTransform();

        private Brush wbrush = Brushes.White;
        private Brush bbrush = Brushes.Blue ;
        private Brush blackBrush = Brushes.Black; 
        private Brush brush ;
        Pen rpen = new Pen(Color.Red, 3);
        Pen blackPen = new Pen(Color .Black ,1);
        Font largeFont = new Font("黑体", 12);
        Font smallFont = new Font("黑体", 8);
        private float yRatioScale;

        public Brush WBrush { get => wbrush; set => wbrush = value; }
        public Pen Rpen { get => rpen; set => rpen = value; }
        public Font LargeFont { get => largeFont; set => largeFont = value; }
        public Font SmallFont { get => smallFont; set => smallFont = value; }
        public Brush Bbrush { get => bbrush; set => bbrush = value; }
        internal float YRatioScale { get => yRatioScale; set => yRatioScale = value; }
        public Brush Brush { get => brush; set => brush = value; }
        public Pen BlackPen { get => blackPen; set => blackPen = value; }
        public Brush BlackBrush { get => blackBrush; set => blackBrush = value; }
    }
}

Platform.cs

威尼斯人线上娱乐 13威尼斯人线上娱乐 14

using System.Drawing;

namespace Chart
{
    public class Windows : Platform 
    {
        private readonly Graphics graphics;

        public Windows(Bitmap bmp)
        {
            graphics = Graphics.FromImage(bmp);
        }

        public override void FillRectangle(Brush b, int x, int y, int width, int height)
        {
            graphics.FillRectangle(b, x, y, width, height);
        }
        public override void DrawLine(Pen pen, Point pt1, Point pt2)
        {
            graphics.DrawLine(pen, pt1, pt2);
        }
        public override void DrawString(string s, Font font, Brush brush, RectangleF layoutRectangle)
        {
            graphics.DrawString(s, font, brush, layoutRectangle);
        }
        public override void DrawString(string s, Font font, Brush brush, float x, float y)
        {
            graphics.DrawString(s, font, brush, x, y);
        }
        public override void FillRectangle(Brush brush, Rectangle rect)
        {
            graphics.FillRectangle(brush, rect);
        }
        public override void TranslateTransform(float dx, float dy)
        {
            graphics.TranslateTransform(dx, dy);
        }
        public override void ResetTransform()
        {
            graphics.ResetTransform();
        }
    }
}

Windows.cs

威尼斯人线上娱乐 15威尼斯人线上娱乐 16

using System.Collections.Generic;
using System.Drawing;
namespace Chart
{
    public class Composition
    {
        private List<DataPoint> dataPoints;
        private string name;
        private Brush brushColor;
        private int max;         

        public List<DataPoint> DataPoints { get => dataPoints; set => dataPoints = value; }
        public string Name { get => name; set => name = value; }
        public Brush BrushColor { get => brushColor; set => brushColor = value; }

        public int Max              //Linq中提供的计算List最大值的方法是集合中的元素即为可比较的数值类型,DataPoint不是,所以这里的方法自定义
        {
            get
            {
                foreach (var datapoint in DataPoints)
                {
                    if (datapoint.YValue >= max)
                    {
                        max = datapoint.YValue;
                    }
                }
                return max;
            }
        }
    }
}

Composition.cs

威尼斯人线上娱乐 17威尼斯人线上娱乐 18

namespace Chart
{
    public class DataPoint
    {
        private string xValue;
        private int yValue;

        public int YValue { get => yValue; set => yValue = value; }
        public string XValue { get => xValue; set => xValue = value; }
    }
}

DataPoint

威尼斯人线上娱乐 19威尼斯人线上娱乐 20

using System.Collections.Generic;
using System.IO;
namespace Chart
{
    public abstract class DataSource
    {
        protected abstract List<Composition> GetDataListCore(string path);  

        public List<Composition> GetDataList(string path)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException(path);
            }
            return GetDataListCore(path);
        }
    }
}

DataSource.cs

威尼斯人线上娱乐 21威尼斯人线上娱乐 22

using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
namespace Chart
{
    public class JsonDataSource : DataSource
    {
        protected override List<Composition> GetDataListCore(string path)
        {
          return  JsonConvert.DeserializeObject<List<Composition>>(File.ReadAllText(path));            
        }
    }
}

JsonDataSource.cs

威尼斯人线上娱乐 23威尼斯人线上娱乐 24

[
  {
    "Name": "Molly",
    "DataPoints": [
      {
        "XValue": "English",
        "YValue": 2
      },
      {
        "XValue": "Chinese",
        "YValue": 6
      },
      {
        "XValue": "Math",
        "YValue": 7
      },
      {
        "XValue": "Art",
        "YValue": 7
      }
    ]
  },
  {
    "Name": "Bob",
    "DataPoints": [
      {
        "XValue": "English",
        "YValue": 9
      },
      {
        "XValue": "Math",
        "YValue": 12
      },
      {
        "XValue": "Art",
        "YValue": 3
      },
      {
        "XValue": "Chinese",
        "YValue": 3
      }
    ]
  },
  {
    "Name": "Angela",
    "DataPoints": [
      {
        "XValue": "English",
        "YValue": 5
      },
      {
        "XValue": "Math",
        "YValue": 13
      },
      {
        "XValue": "Art",
        "YValue": 9
      },
      {
        "XValue": "Chinese",
        "YValue": 6
      }
    ]
  }

]

JSON.json

以下附上这一个顺序设计的UML类图

威尼斯人线上娱乐 25

 


相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图